mysql语句

一个状态多统计

    select r.region_name as name,count(if(d.status in(1,2),true,null)) as value,
    count(d.status=0 or null) as secondValue from duty_record  d left join region r on d.org_id = r.id
    where  d.org_id = '#(orgId)' AND d.record_time BETWEEN (CASE WHEN '#(insert_time)' is null then  d.record_time ELSE '#(insert_time)' end)
    AND (CASE WHEN '#(endtime)' is null then  d.record_time ELSE '#(endtime)' end) group by r.id
    UNION  ALL
    select r.region_name as name,count(if(d.status in(1,2),true,null)) as value,
    count(d.status=0 or null) as secondValue from duty_record  d left join region r on d.org_id = r.id
    where  r.parent_id = '#(orgId)' AND  d.record_time BETWEEN (CASE WHEN '#(insert_time)' is null then  d.record_time ELSE '#(insert_time)' end)
          AND (CASE WHEN '#(endtime)' is null then  d.record_time ELSE '#(endtime)' end) group by r.id;

查询当月信息

SELECT count(if(status in(1,2),true,null)) as finish,
count(status=0 or null) as backlog FROM duty_record WHERE DATE_FORMAT( record_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) and org_id = '#(orgId)'

//删除多表
delete m ,d,dd from organization_member m right JOIN organization_dept d on m.org_id =d.id
right JOIN organization_directory dd on dd.id = d.directory_id
right JOIN basic_information b on b.id = dd.basic_id
where b.id =#para(0)

你可能感兴趣的:(java)