Postgres无法正确排序两列

编程入门 行业动态 更新时间:2024-10-23 05:51:06
本文介绍了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无法正确排序两列

本文发布于:2023-10-16 16:21:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498081.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   Postgres

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!