ITeye博客

常见自定义方法

qinya06 · 2021-08-31 17:30 · mysql · 数据库 · SQL · Markdown

CREATE DEFINER=`bar`@`%` FUNCTION `statisticalDay`(time datetime) RETURNS varchar(50) CHARSET utf8
    DETERMINISTIC
begin
declare temp varchar(50) DEFAULT '';
select if(hour(time) < 8 or (hour(time)<9 and MINUTE(time)<30) ,DATE_FORMAT(date_add(time,interval -1 DAY),'%Y-%m-%d') ,DATE_FORMAT(time,'%Y-%m-%d')) into temp;
return temp;
end


select  *  from  t_table where statisticalDay(F_Createime)='2021-03-21'

select  GROUP_CONCAT(F_Sn   ORDER BY 'f_sn' desc    ) from  gaslog GROUP BY F_Machine

53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,22,21,20,19,18,17,16,15,14,13,12,11,10,9


select * from gaslog as b where not exists(select 1 from gaslog where F_Machine= b.F_Machine
and b.F_Sn<F_Sn )

分组取最新数据


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。