select
count(id) as num,
ym as certificationDateStr,
area_id as areaId
from (select t.area_id, t.id, to_char(t.certification_date, 'yyyy-MM') ym
from spcy_license t
t.CHARGE_PERSON_TYPE = #chargePersonType#
t.CERTIFICATION_DATE between #certificationDate# and #endCertificationDate#
t.CHARGE_PERSON_NAME like '%$chargePersonName$%'
t.PERMIT_NO = #permitNo#
t.FOOD_SAFETY_ADMIN like '%$foodSafetyAdmin$%'
t.ECONOMY_NATURE = #economyNature#
t.COMPANY_NAME like '%$companyName$%'
t.LICENSE_TYPE = #licenseType#
t.AREA_ID like '$areaId$%'
t.STATUS = #status#
)
group by ym, area_id order by certificationDateStr desc
你可以参考下这个,这个是个统计查询的ibatIS sqlMap
select classid,sum(case when avgscore<60 then 1 else 0 end )as failure,
sum(case when (avgscore >= 60 and avgscore<90) then 1 else 0 end )as pass,
sum(case when avgscore > 90 then 1 else 0 end )as highgrade,
sum(case when (avgscore >= 60) then 1 else 0 end )/count(*)*100 || '%' as passrate
from class
group by classid;
上面的语句,用case when 判断,然后sum()统计,希望是你需要的答案,o(∩_∩)o
使用CASE ... WHEN ....