mysql根据其中一个字段排序后去最新数据

2021/7/2 19:23:30

本文主要是介绍mysql根据其中一个字段排序后去最新数据,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

第一种方法:

SELECT
SUBSTRING_INDEX(GROUP_CONCAT(to_user_code ORDER BY eppntur.modify_time desc),',',1)

-- GROUP_CONCAT(user_code ORDER BY eppntur.modify_time desc)
FROM
es_project_process_node_to_user_ref eppntur
WHERE
eppntur.disabled = 'FALSE'

AND eppntur.ppnu_code in ('PPNU202105241547132385730','PPNU202106111538184828409')
GROUP BY
eppntur.ppnu_code ORDER BY eppntur.modify_time desc

第二种方法:

SELECT
temp.bpnu_code AS bpnuCode,
temp.book_type AS bookType,
temp.page_num AS pageNum,
temp.node_code AS nodeCode,
(
SELECT
node_name
FROM
es_node
WHERE
node_code = temp.node_code
) AS nodeName,
(
SELECT
GROUP_CONCAT(eu.user_name)
FROM
es_book_process_node_to_user_ref bpntur
LEFT JOIN es_user eu ON (
eu.user_code = bpntur.to_user_code
)
WHERE
bpntur.disabled = 'FALSE'
AND bpntur.bpnu_code = temp.bpnu_code
AND bpntur. STATUS != 'UBABLED'
) AS assignUserName,
(
SELECT
GROUP_CONCAT(bpntur.to_user_code)
FROM
es_book_process_node_to_user_ref bpntur
WHERE
bpntur.disabled = 'FALSE'
AND bpntur.bpnu_code = temp.bpnu_code
AND bpntur. STATUS != 'UBABLED'
) AS assignUserCode,
CASE
WHEN temp. STATUS = 'WAITING_ACTIVATE' THEN
'UNALLOCATED'
WHEN temp. STATUS = 'WAITING_CLAIM' THEN
'UNCLAIMED'
WHEN temp. STATUS = 'TO_FINISH' THEN
'CLAIMED'
ELSE
''
END AS state
FROM
(
SELECT
*
FROM
es_book_process_node_from_user_ref
WHERE
disabled = 'FALSE'
AND book_code = #{bookCode}
AND book_type != 'ALL'
AND page_num != 'ALL'
ORDER BY
modify_time DESC
LIMIT 1000
) AS temp
GROUP BY
temp.book_type,
temp.page_num
ORDER BY
temp.book_type



这篇关于mysql根据其中一个字段排序后去最新数据的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程