gpt4 book ai didi

mysql - 如何根据select语句对行进行排序

转载 作者:行者123 更新时间:2023-11-29 07:33:43 25 4
gpt4 key购买 nike

所以我有疑问:

SELECT t1.username, t1.staff_id, t1.longname, t2.*, t3.longname as appraisor_name, t4.dep, t2.staff_id as check_id, t5.deptname FROM users t1
LEFT JOIN(
SELECT * FROM quartz_quarter2 WHERE staff_id = '1001128' AND date = '2017'
UNION
SELECT * FROM quartz_quarter3 WHERE staff_id = '1001128' AND date = '2017'
UNION
SELECT * FROM quartz_quarter4 WHERE staff_id = '1001128' AND date = '2017'
UNION
SELECT * FROM quartz_quarter1 WHERE staff_id = '1001128' AND date = '2018'
)t2 ON t1.staff_id = t2.staff_id
LEFT JOIN( SELECT * FROM users )t3 ON t2.appraisor_id = t3.staff_id
LEFT JOIN( SELECT * FROM quartz_department )t4 ON t2.role = t4.role
LEFT JOIN( SELECT * FROM ref_department )t5 ON t1.fkdeptid = t5.deptid
WHERE t1.staff_id = '1001128'

我想按照我选择的顺序获取数据,所以它应该是:

| username | staff_id | quarter |
+++++++++++++++++++++++++++++++++
| YEVGENIY | 1001128 | 2 |
| YEVGENIY | 1001128 | 3 |
| YEVGENIY | 1001128 | 4 |
| YEVGENIY | 1001128 | 1 |

但我得到的是:

enter image description here

有什么办法可以根据select语句排序吗?

最佳答案

您可以使用 FIND_IN_SET()功能。

ORDER BY FIND_IN_SET(quarter, '2,3,4,1);

此函数将返回值在指定集合中的位置。

关于mysql - 如何根据select语句对行进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49890194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com