【发布时间】:2023-03-31 11:10:02
【问题描述】:
如何为以下场景构造查询:
我有三张桌子:
- 人
- 书籍(与
peopleserno上的人相关联) - 视频(与
peopleserno上的人相关联)
我想创建一个 SQL,其中输出给出一行,其中包含特定人阅读/观看的书籍和视频的数量。
示例输出:
John | 3 (books) | 2 (videos)
我尝试过这样的事情,但它不起作用:
select a.name,
count(b.serno) as books,
count(c.serno) as videos
from people a,
books b,
videos c
where a.serno = b.peopleserno
and a.serno = c.peopleserno
谢谢。
【问题讨论】: