Ibatis如何查询多项统计信息

2025-02-22 11:25:05
推荐回答(3个)
回答1:

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

回答2:

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

回答3:

使用CASE ... WHEN ....