Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两张桌子。一个叫 HOSTS,一个叫 GUESTS。HOSTS表包括:
* hid * firstname * lastname * email
hid是唯一的主机标识符,它是一个整数、主键并自动递增。
GUESTS表包括:
* gid * hid * gfname * glname
gid是唯一的访客标识符,它是一个整数、主键并自动递增。
所需的输出是在每一行显示 HOSTS 和每个主机拥有的客人总数(数字)。
名字姓氏电子邮件“客人总数”
如何做到这一点?
加入表格,然后对结果进行分组:
SELECT HOSTS.*, COUNT(gid) FROM HOSTS LEFT JOIN GUESTS USING (hid) GROUP BY hid