首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

简单有关问题,搞定马上结贴

2012-03-30 
简单问题,请教高手,搞定马上结贴 Selectsum(InMoney)as系统总充值额fromeinOutMoneywhereKindin(100,105,1

简单问题,请教高手,搞定马上结贴

Select   sum(InMoney)   as   系统总充值额   from   einOutMoney   where   Kind   in   (100,105,107,201,101)   and   UseType   <> 7
union   all
select   sum(saveMoney)   as   补助总额   from   eSaveMoney   where   UseType=7
union   all
Select   sum(COnsumeMOney)   as   系统消费总额   from   eCOnsumeData
union   all
Select   sum(CardValue)   as   系统卡余总额   from   cCard  
union   all
select   sum(OutMoney)   as   退款总额   from   eInOutMoney   where   kind   in(102,106,156)
union   all
Select   sum(InMoney)   as   收押金总额   from   einOutMoney   where   Kind=50
union   all
Select   sum(OutMoney)   as   退押金总额   from   eInOutMoney   where   Kind=52

我这样得到的记录是一个字段,N多行,我现在想要的是1行,包含N个字段
要怎么改,请指教

[解决办法]
select * from (
Select sum(InMoney) as 系统总充值额 from einOutMoney where Kind in (100,105,107,201,101) and UseType <> 7)a
cross join (
select sum(saveMoney) as 补助总额 from eSaveMoney where UseType=7)b
cross join (
Select sum(COnsumeMOney) as 系统消费总额 from eCOnsumeData)c
cross join (
Select sum(CardValue) as 系统卡余总额 from cCard )d
cross join (
select sum(OutMoney) as 退款总额 from eInOutMoney where kind in(102,106,156))e
cross join (
Select sum(InMoney) as 收押金总额 from einOutMoney where Kind=50)f
cross join (
Select sum(OutMoney) as 退押金总额 from eInOutMoney where Kind=52)g
[解决办法]
union all不对啊,呵呵 !这样只会有一列
cross join 可以产生多列(笛卡尔集合)
但是我看这个查询怎么这么别扭啊!

热点排行