0
我有一個用戶DE9013與SQL表兩個正評級:PostgreSQL的:having子句未正常工作
# select * from pref_rep where id='DE9013';
id | author | good | fair | nice | about | last_rated | author_ip
--------+--------+------+------+------+-------+----------------------------+---------------
DE9013 | DE9241 | t | t | t | | 2011-03-06 09:23:00.400518 | 97.33.154.43
DE9013 | DE9544 | t | t | t | | 2011-03-06 10:06:37.561277 | 97.33.35.54
(2 rows)
和公平 + 不錯收視率的總和爲預計四:
# select
count(nullif(r.fair, false)) +
count(nullif(r.nice, false)) -
count(nullif(r.fair, true)) -
count(nullif(r.nice, true))
from pref_rep r where id='DE9013';
?column?
----------
4
(1 row)
我的問題是:爲什麼會出現在列表中的用戶是低,在那裏我試圖找到所有玩過超過30個已完成遊戲的用戶,並且評分(公平 + 漂亮)高於30?
# select substring(m.id from 3)::bigint, 3
from pref_match m, pref_rep r
where m.id=r.id and
m.id like 'DE%'
group by m.id
having (sum(m.completed) > 30 and
count(nullif(r.fair, false)) +
count(nullif(r.nice, false)) -
count(nullif(r.fair, true)) -
count(nullif(r.nice, true)) > 30) limit 3;
substring | ?column?
-----------+----------
9013 | 3
8692 | 3
7059 | 3
(3 rows)
使用PostgreSQL 8.4.7在CentOS 5.7/64位