表里有一个字符串类型的评估时间(年月日时分秒),需要在sql里实现不跨年时,显示为“ 月 日 时 分 秒 ”;跨年即每一年一月一日第一条数据显示为”年 月 日 时 分 秒“,如何只写sql就能达成
select case when b.mindate is null then 年到秒 else 月到秒,其它字段 from 表名 a
left join (select year(日期) as yy,min(日期) as mindate from 表名 group yy) b on b.mindate=a.日期
依此参考,答题不容易,顺手请采纳
用case when 能达成