sql记录
统计查询
select t.group_code as group_code,
case when t.app_key = 'sbcsh' and t.sz = 'zzsybnsr' then count(*) else 0 end as csh_total,
case when t.app_key = 'sbqc' then count(*) else 0 end as sbqc_total,
case when t.app_key = 'sbtj' then count(*) else 0 end as sbtj_total,
case when t.app_key = 'sbjk' then count(*) else 0 end as sbjk_total
from t_bwprocess_bw t
where t.create_time>='2020-11-01' and t.create_time<'2020-11-30'
group by t.app_key,t.group_code
SELECT e.last_name,j.grade_level FROM employees e,job_grades j WHERE e.salary BETWEEN j.lowest_sal AND j.highest_sal;
日期查询
#获取当月最后一天
select last_day(curdate());
#获取本月的第一天
select date_add(curdate(),interval -day(curdate())+1 day) ;
#获取下个月的第一天
select date_add(curdate() - day(curdate()) +1,interval 1 month );
#获取当前月已过了几天
select day(curdate());
#获取当前月的天数(先加一个月,再减今天是第几天,得到当前月的最后一天,最后求最后一天是几号)
select day(date_add( date_add(curdate(),interval 1 month),interval -day(curdate()) day ));
#上个月的第一天
select date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(
day from now())-1 day),interval 1 month)
#上个月的最后一天:
select date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(
day from now()) day),interval 0 month) as date
#这个月的第一天:
select date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(
day from now())-1 day),interval 0 month)
浙公网安备 33010602011771号