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;