以前写的语句: SELECT 生成时间 FROM result WHERE `型号`='1' ORDER BY 生成时间 DESC LIMIT 1; SELECT 生成时间 FROM result WHERE `型号`='2' ORDER BY 生成时间 DESC LIMIT 1; SELECT 生成时间 FROM result WHERE `型号`='3' ORDER BY 生成时间 DESC LIMIT 1;
生成时间是 datatime 程序拿到结果后,再本地算法算出最小(时间最早的值) 请问如果在 Mysql 语句上,如何实现一句出结果呢? `型号`='3'很有可能没有存在。。。
@coderfox #20 更正一下,只需要 SELECT 型号, MAX(生成时间) FROM test WHERE 型号 IN ('1', '2', '3') GROUP BY 型号;
jzmws
2020-08-28 09:54:53 +08:00
考虑用 case ?
bigpower777
2020-08-28 16:54:46 +08:00
SELECT s1.d1, s2.d2, s3.d3 FROM (select CREATE_DATE as d1 from account_system where MZ='01' ORDER BY CREATE_DATE desc limit 1) s1, (select CREATE_DATE as d2 from account_system where MZ='02' ORDER BY CREATE_DATE desc limit 1) s2, (select CREATE_DATE as d3from account_system where MZ='03' ORDER BY CREATE_DATE desc limit 1) s3