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

50分!sql查询解决思路

2012-02-28 
50分!!sql查询selectcount(1) as 北京, sum(TFT_TRNAMT) as 金额,left( TFT_DTE,6) as monthfromABST_Tr

50分!!sql查询
select  
count(1) as '北京'
 , sum(TFT_TRNAMT) as 金额
 ,left( TFT_DTE ,6) as month 
 from ABST_TrnFlw group by left( TFT_DTE ,6)
order by month  

select sum(TFT_TRNAMT) as 分发金额
,left( TFT_DTE ,6) as month 
from ABST_TrnFlw where TFT_TRNFIG='1' 
group by left( TFT_DTE ,6)

现在把2个表格利用 month 左连接,
谢谢 帮忙拼起来。

[解决办法]
select * from 
(select
count(1) as '北京' 
, sum(TFT_TRNAMT) as 金额 
,left( TFT_DTE ,6) as month 
from ABST_TrnFlw group by left( TFT_DTE ,6) 
order by month ) a1
left join

(select sum(TFT_TRNAMT) as 分发金额 
,left( TFT_DTE ,6) as month 
from ABST_TrnFlw where TFT_TRNFIG='1' 
group by left( TFT_DTE ,6)) a2 
on a1.month=a2.month
[解决办法]

SQL code
select *from (select count(1) as '北京', sum(TFT_TRNAMT) as 金额 ,left( TFT_DTE ,6) as month from ABST_TrnFlw group by left( TFT_DTE ,6)) a left join (select sum(TFT_TRNAMT) as 分发金额,left( TFT_DTE ,6) as month from ABST_TrnFlw where TFT_TRNFIG='1' group by left( TFT_DTE ,6)) b on a.month=b.month 

热点排行