一开始是用注释(图1)来得到想要的结果,后来搜索得知可以用union all来合并语法,但是多了很多语句(图2),请问该怎么缩减语法。
select count(*)保有量 from trff_app.vehicle
where substr(cllx,1,2) in ('H1','Q1')
union all
select count(*)保有量 from trff_app.vehicle
where substr(cllx,1,2) in ('B1','G1')
union all
select count(*)保有量 from trff_app.vehicle
where syxz='R'
union all
select count(*)保有量 from trff_app.vehicle
where syxz='B'and substr(cllx,1,2)='K1'
union all
select count(*)保有量 from trff_app.vehicle
where syxz='E'and substr(cllx,1,2)='K1'
这个语句因为where语句的条件值不一样,只能使用union
select count(*)保有量 from trff_app.vehicle where substr(cllx,1,2) in ('H1','Q1','B1','G1','K1') and syx in('R','B','E' )
select count(*)保有量 from trff_app.vehicle where substr(cllx,1,2) in ('H1','Q1') or substr(cllx,1,2) in ('B1','G1') or syxz='R' or syxz='B'and substr(cllx,1,2)='K1' or syxz='E'and substr(cllx,1,2)='K1'