SQL 计算表A字段在表B字段中出现的次数

SELECT A.Id,A.Name,COUNT(B.LiveID) AS count from SetLiveHistory B RIGHT JOIN Live A ON B.LiveId=A.Id GROUP BY A.Id,A.Name ORDER BY count;

 

附加条件:

select A.Id,A.Name,COUNT(B.LiveID) as count from
(select * from SetLiveHistory where time >= '2020-03-1') B
right join Live A ON B.LiveId=A.Id group by A.Id,A.Name order by count;

 


https://ask.csdn.net/questions/749402

posted @ 2020-03-31 00:30  冬音  阅读(727)  评论(0编辑  收藏  举报