SQL三表关联查询求教,高分 急!!

发布网友 发布时间:2024-10-23 18:16

我来回答

6个回答

热心网友 时间:2024-11-01 19:23

SELECT *
FROM A,B,C
WHERE A.USERID = C.USERID
AND B.ID = C.ID
AND B.NAME = '某某'
AND A.TIME = '2013.1.1'
--统计记录数
SELECT COUNT(1)
FROM A,B,C
WHERE A.USERID = C.USERID
AND B.ID = C.ID
AND B.NAME = '某某'
AND A.TIME = '2013.1.1'追问不能统计记录数写在一个语句里吗?

追答SELECT COUNT(1) OVER(PARTITION BY B.NAME) REC_COUNT,
A.UserID , B. ID , B.Name , B.ComPany , A.Time
FROM A,B,C
WHERE A.USERID = C.USERID
AND B.ID = C.ID
AND B.NAME = '某某'
AND A.TIME = '2013.1.1'
哎呀我去,你就不能自己动动手写写

热心网友 时间:2024-11-01 19:24

SELECT A.UserID , B. ID , B.Name , B.ComPany , A.Time

FROM A,B,C
WHERE A.UserID = C.UserID AND B.ID = C.ID
AND B.NAME = '某某'
AND A.TIME = '2013.1.1'
--时间这里的话,需要与你表中的格式一致
------------------------------------
还要看你是什么数据库了,不同的库语法有差异

热心网友 时间:2024-11-01 19:24

把查询看成一个表来用
select Name,count (*) from
(
SELECT A.UserID,B.ID,B.Name,B.Company,A.Time
from A A,B B,C C
WHERE A.UserID=C.UserID AND B.ID=C.ID
AND B.Name='某某' AND A.Time='2013.1.1'
group by A.UserID,B.ID,B.Name,B.Company,A.Time
)

热心网友 时间:2024-11-01 19:25

select
A.UserID , B. ID , B.Name , B.ComPany , A.Time

FROM A,B,C WHERE A.UserID =C.UserID AND b.ID=C.id
AND B.Name=某某 A.Time=2013.1.1

热心网友 时间:2024-11-01 19:26

直接上sql语句吧

select a.UserID,b.ID,c.Name,c.Company,a.Time from A a inner join C b on a.UserID=b.UserID

left join B c on b.ID=c.ID where c.Name='某某' and a.Time='2013.1.1'

即可完成该功能!

热心网友 时间:2024-11-01 19:26

楼上都一样的,至于你说的
UserID的总记录,你看一下查询的右下方有多少行就是了
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com