我有这个查询,我将结果联合起来,然后对它们进行分组。我回答here。也将它贴在下面:
Select driver.Booklet_type, SUM(cs.End_Leaf_No - cs.Start_Leaf_No +1) as No_of_Coupons
from (select 'GR' as Booklet_type union all
select 'PI'
) driver left outer join
Coupon_Sale cs
on driver.Booklet_Type = cs.Booklet_Type and
date_format(cs.Booklet_Sale_Date, '%Y%m') = :ccyymm and
cs.Booklet_type in ('GR', 'PI')
group by driver.Booklet_Type;
我得到的结果是:
Booklet_Type | No_of_Coupons
========================
GR | 3
PI | 1
现在我有另一个按金额分组的查询,其结果如下:
Amount | Count
========================
25 | 3
10 | 1
现在我想在上面的GR行中添加3的计数,在PI行中添加1的计数。
我该怎么做?
第二个表的查询是:
select payment_amount,count(p_id)
from p
where p_id in (463,464,465,466,467,468,469,470,471,472,473,474,475,476)
group by payment_amount