gpt4 book ai didi

mysql - 在 where 子句中按条件顺序获取记录

转载 作者:可可西里 更新时间:2023-11-01 07:52:34 27 4
gpt4 key购买 nike

select id,title,release_date 
from tbl_movies
where release_date > '2014-02-20' or release_date=''
order by release_date asc
 "id" |  "title"                "release_date"  "49" |  "Fandry"               |  ""  "92" |  "Govinda"              |  ""   "112"|  "Gadad Jambhal"        |   ""  "114"|  "Aandhali Koshimbir"   |   ""  "118"|  "Mee Aani U"           |   ""  "125"|  "Tapal"                |   ""   "131"|  "Cappuccino"           |    ""  "129"|  "Sau Shashi Deodhar"   | "2014-02-21"  "130"|  "Yellow"               | "2014-03-28" 

我希望最后两条记录在前,我不能使用 desc 因为结果是基于升序日期的,最后两条记录基于第一个条件,我该如何实现

最佳答案

试试这个

SELECT id,title,release_date 
FROM tbl_movies
WHERE release_date > '2014-02-20' or release_date=''
ORDER BY CASE WHEN release_date = '""' Then 1 Else 0 End,DATE(release_date) ASC

关于mysql - 在 where 子句中按条件顺序获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22398681/

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