一直很少用SQL情况是这样的A表记录了用户信息,包括id,name等
B表记录了用户的登录信息,包括uid,ip等我现在想统计每个用户的登录次数,自己想到了右连接,但是貌似当右边表为空时就数据没有了。
SELECT id,name, count(*) cnt
FROM user as A
RIGHT JOIN login as B ON A.id = B.uid
GROUP BY uid
因为我需要把每位用户都显示出来,即使他在B表没有记录,也要显示为0
B表记录了用户的登录信息,包括uid,ip等我现在想统计每个用户的登录次数,自己想到了右连接,但是貌似当右边表为空时就数据没有了。
SELECT id,name, count(*) cnt
FROM user as A
RIGHT JOIN login as B ON A.id = B.uid
GROUP BY uid
因为我需要把每位用户都显示出来,即使他在B表没有记录,也要显示为0
SELECT id,name, count(*) cnt
FROM user as A
left JOIN login as B ON A.id = B.uid
GROUP BY id
from a left join b
on a.id = b.uid
group by a.id , a.name
#1582 - Incorrect parameter count in the call to native function 'isnull'
FROM [user] as A
LEFT JOIN
(SELECT uid,count(1) as cnt from [login] GROUP BY uid) as B
ON A.id = B.uid
不好意思,忘记说了,我用的是MYSQL,
报错是#1582 - Incorrect parameter count in the call to native function 'isnull'