我需要選擇一個屬性擁有者,擁有最多數量的未被潛在買家查看的屬性。選擇最大空值
什麼是最好的方式來選擇「propertyforrent.ownerno」,其中'propertyno IS NULL'的數量是最高的。
這:
SELECT PropertyForRent.ownerno
FROM PropertyForRent propertyforrent, Client client, Viewing viewing
WHERE client.preftype=propertyforrent.type
AND client.clientno=viewing.clientno
AND viewing.propertyno IS NULL
ORDER BY count(*)
LIMIT 1
或本:
SELECT PropertyForRent.ownerno
FROM PropertyForRent propertyforrent, Client client, Viewing viewing
WHERE client.preftype=propertyforrent.type
AND client.clientno=viewing.clientno
AND MAX(COUNT(viewing.propertyno IS NULL)
謝謝!
請沒有在SQL'NULL'有特殊待遇。 NULL值不等於任何值,包括另一個NULL值。你需要在你的查詢中使用'IS NULL'。 –
含義而不是說'='NULL''我不得不說'IS NULL'吧? – am340
是的。你說對了。順便說一句,還有'不是空'。 –