所以我无法解决这个问题:
我需要显示这些表中拥有最多属性的人的姓名和电话号码:
所有者:
ownerno | fname | lname | telno
_________________________________
B6 | John | g | 67869
_________________________________
B5 | Tom | f | 46876
_________________________________
B4 | Sally | s | 23456
_________________________________
B3 | Ann | a | 23786
Propertyowned:
propertyno | ownerno
_____________________
BH5 | B6
_____________________
BG6 | B5
_____________________
BJ7 | B6
_____________________
BF5 | B5
_____________________
BD4 | B4
希望你能帮助我 感谢
答案 0 :(得分:1)
SELECT
o.fname,
o.lname,
o.telno,
count(p.propertyno) as property_count
FROM
owners o
INNER JOIN
Propertyowned p
ON p.ownerno = o.ownerno
GROUP BY
o.fname,
o.lname,
o.telno
ORDER BY
count(p.propertyno) DESC
答案 1 :(得分:0)
这应该做:
SELECT
count(p.propertyno) as numproperties,
o.fcname,
o.lname, o.telno
FROM
property p,
owner o
WHERE
o.ownerno = p.ownerno
GROUP BY
o.ownerno
ORDER BY
numproperties desc
LIMIT 1