Postgres无法正确排序两列 [英] Postgres not sorting two columns correctly
本文介绍了Postgres无法正确排序两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从Postgres中选择一个名称,一个动作和一个计数,按名称ASC,动作ASC进行排序,如下所示:
I am selecting a name, an action and a count from Postgres sorting by name ASC, action ASC like so:
SELECT u.firstname || ' ' || u.surname AS user,
nt.name AS action,
cn.count
FROM (
SELECT actioned_by_id, note_type_id, COUNT(id) AS count
FROM customer_notes
WHERE actioned_date IS NOT NULL
GROUP BY actioned_by_id, note_type_id
) AS cn
LEFT JOIN note_type AS nt ON cn.note_type_id = nt.id
LEFT JOIN users as u on cn.actioned_by_id = u.id
WHERE cn.actioned_by_id IS NOT NULL
ORDER BY user, action;
但是结果表明它忽略了user子句,仅按动作排序。
however the results show that it is ignoring the user clause and only ordering by the action.
"ADMIN USER" "CALL OUT" 1
"ADMIN USER" "EMAIL" 1
"ADMIN USER" "LETTER" 2
"AA AA" "MEETING" 1
"ADMIN USER" "PHONECALL" 7
"AA AA" "PHONECALL" 1
有人知道为什么吗?
以及如何使其正确订购?
Anyone understand why? And how to make it order properly?
推荐答案
user
是保留字-返回当前用户名
user
is a reserved word - returning the current user name
尝试
order by u.firstname || ' ' || u.surname, action
这篇关于Postgres无法正确排序两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文