如果添加
SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY';
然後你會看到爲什麼其他RDBMS不會允許這種語法:在SELECT
- 3未聚集列,但一個在GROUP BY
- ORDER BY列不在GROUP BY/SELECT和未聚集
如果你想GROUP BY而不是DISTINCT,那麼你就需要GROUP BY所有列在SELECT
SELECT s.serviceid, s.servicenameit, s.servicenameen
FROM services s, kpi k, checklist_has_kpi chk
WHERE s.serviceid=k.serviceid AND k.kpiid=chk.kpiid AND k.inreport='yes' AND chk.checklistid=61
GROUP BY s.serviceid, s.servicenameit, s.servicenameen
但你有沒有chk.order
訂購通過,無論是使用GROUP BY或DISTINCT
所以那麼這個怎麼樣,完全忽略重複?
SELECT s.serviceid, s.servicenameit, s.servicenameen
FROM services s, kpi k, checklist_has_kpi chk
WHERE s.serviceid=k.serviceid AND k.kpiid=chk.kpiid AND k.inreport='yes' AND chk.checklistid=61
ORDER BY chk.order ASC
或者這ORDER BY每3分services
列
SELECT s.serviceid, s.servicenameit, s.servicenameen
FROM services s, kpi k, checklist_has_kpi chk
WHERE s.serviceid=k.serviceid AND k.kpiid=chk.kpiid AND k.inreport='yes' AND chk.checklistid=61
GROUP BY s.serviceid, s.servicenameit, s.servicenameen
ORDER BY MIN(chk.order)
來源
2011-09-16 11:40:53
gbn
那麼你所期望的結果最早次序? – Jacob
你有錯誤嗎?結果是否按照預期排序? –