[难]:高手帮看看一个sql语句怎么写
我打上句语查的内容
select place_name,explanatory,bill_autoid from diary_air
张影确认出票 960
张秀萍修改新订单959
周玲玲确认出票 961
张秀萍修改新订单959
张影新预订单 962
张影确认出票 962
周玲玲确认出票 963
张秀萍修改新订单959
张影新预订单 964
李娜确认出票 958
我打下面的语。他是这个。id是对应的
select bill_autoid,bill_source from bill
965携程
966公司资源
967公司资源
968携程
969携程
970公司资源
971公司资源
972公司资源
现在我想做统计。姓名列出来,确认出票的有几条计录,bill_source为 "携程 "
的有几条记录。没有 "携程的有几条,列这么四个字段
"
[解决办法]
需求不是很清楚,在说明白一点
[解决办法]
将两个表联合查询,查询的结果插入一个临时表!然后在临时表查询 group by place_name,bill_source
[解决办法]
select
tab1.place_name
, tab1.explanatory
, explanatorynum = tab1.num1
, tab2.bill_source
, bill_sourcenum = tab2.num1
from(
select place_name, explanatory, num1 = count(explanatory)
from diary_air
where explanatory = '确认出票 '
group by place_name, explanatory
) tab1 left join
(
select
da.place_name, bi.bill_source, num1 = count(bi.bill_source)
from diary_air da left join bill bi
on da.bill_autoid = bi.bill_autoid
where bi.bill_source = '携程 '
group by da.place_name, bi.bill_source
) tab2
on tab1.place_name = tab2.place_name