---身上的披肩数量
select count(e1.shoulder) number from ec_role e1,ec_equipment e2 where e1.shoulder =e2.id and e2.name like '%披肩%'
---背包中的披肩数量
select count(t1.prop_id)  number from ec_role_property t1, ec_equipment t2 where t1.prop_id=t2.id and t1.type='0' and t2.name like '%披肩%'
----寄售中的披肩数量
select count(t1.item_id)   number from ec_merchant_second_sale t1,ec_equipment t2 where t1.item_id=t2.id and t2.name like '%披肩%'
----邮件中的披肩数量
select count(t1.equipment)   number from ec_mail t1,ec_equipment t2 where t1.equipment =t2.id and t2.name like '%披肩%'如何将上面的几个number字段给加起来啊,用一条sql语句。

解决方案 »

  1.   

    最直接的select sum(number) as totalnumber
    from
    (
    ---身上的披肩数量
    select count(e1.shoulder) number from ec_role e1,ec_equipment e2 where e1.shoulder =e2.id and e2.name like '%披肩%'
    union all
    ---背包中的披肩数量
    select count(t1.prop_id)  number from ec_role_property t1, ec_equipment t2 where t1.prop_id=t2.id and t1.type='0' and t2.name like '%披肩%'
    union all
    ----寄售中的披肩数量
    select count(t1.item_id)  number from ec_merchant_second_sale t1,ec_equipment t2 where t1.item_id=t2.id and t2.name like '%披肩%'
    union all
    ----邮件中的披肩数量
    select count(t1.equipment)  number from ec_mail t1,ec_equipment t2 where t1.equipment =t2.id and t2.name like '%披肩%' 
    ) t
      

  2.   

    select sum(number) as totalnumber
    from
    (
    ---身上的披肩数量
    select count(e1.shoulder) number from ec_role e1,ec_equipment e2 where e1.shoulder =e2.id and e2.name like '%披肩%'
    union all
    ---背包中的披肩数量
    select count(t1.prop_id)  number from ec_role_property t1, ec_equipment t2 where t1.prop_id=t2.id and t1.type='0' and t2.name like '%披肩%'
    union all
    ----寄售中的披肩数量
    select count(t1.item_id)  number from ec_merchant_second_sale t1,ec_equipment t2 where t1.item_id=t2.id and t2.name like '%披肩%'
    union all
    ----邮件中的披肩数量
    select count(t1.equipment)  number from ec_mail t1,ec_equipment t2 where t1.equipment =t2.id and t2.name like '%披肩%' 
    ) t
      

  3.   

    select sum(number) from
    (
    select count(e1.shoulder) number from ec_role e1,ec_equipment e2 where e1.shoulder =e2.id and e2.name like '%披肩%' 
    union all
    select count(t1.prop_id)  number from ec_role_property t1, ec_equipment t2 where t1.prop_id=t2.id and t1.type='0' and t2.name like '%披肩%' 
    union all
    select count(t1.item_id)  number from ec_merchant_second_sale t1,ec_equipment t2 where t1.item_id=t2.id and t2.name like '%披肩%' 
    union all
    select count(t1.equipment)  number from ec_mail t1,ec_equipment t2 where t1.equipment =t2.id and t2.name like '%披肩%' 
    )
    tt
      

  4.   

    还可以这样select sum(T1.number)+sum(T2.number)+sum(T3.number)+sum(T4.number)
    from 
    (
    select count(e1.shoulder) number from ec_role e1,ec_equipment e2 where e1.shoulder =e2.id and e2.name like '%披肩%' 
    )T1,
    (
    select count(t1.prop_id)  number from ec_role_property t1, ec_equipment t2 where t1.prop_id=t2.id and t1.type='0' and t2.name like '%披肩%' 
    )T2
    ,
    (
    select count(t1.item_id)  number from ec_merchant_second_sale t1,ec_equipment t2 where t1.item_id=t2.id and t2.name like '%披肩%' 
    )T3
    ,
    (
    select count(t1.equipment)  number from ec_mail t1,ec_equipment t2 where t1.equipment =t2.id and t2.name like '%披肩%' 
    )
    T4