日期:2014-05-18  浏览次数:20606 次

没有为第 1 列(属于 'A')指定列。怎么修改了
select time = coalesce(year(a.sale_addtime),year(b.saleout_addtime)),
salemoney = isnull(convert(decimal(18,2),a.sale_money), 0) from (select year(sale_addtime),sale_amount =sum(convert(decimal(18,2),c.item_amount)) from x_sale b left join x_saleitem c on c.item_sale=b.sale_code left join x_product d on d.pro_id=c.item_pro where 1=1 group by year(sale_addtime)) A full join (select year(saleout_addtime),saleout_amount =sum(convert(decimal(18,2),c.item_amount)) from x_saleout b left join x_saleoutitem c on c.item_saleout=b.saleout_code left join x_product d on d.pro_id=c.item_pro where 1=1 group by year(saleout_addtime)) B on A.sale_addtime = B.saleout_addtime

是什么原因了,我想按年综计实际销售数量,如2012,2013年等

------解决方案--------------------
SQL code

select    time = coalesce(year(a.sale_addtime),year(b.saleout_addtime)),
        salemoney = isnull(convert(decimal(18,2),a.sale_money), 0) 
from   (
        select year(sale_addtime) AS col1,
        sale_amount =sum(convert(decimal(18,2),c.item_amount)) 
        from x_sale b    left join x_saleitem c on c.item_sale=b.sale_code 
                        left join x_product d on d.pro_id=c.item_pro 
        where 1=1 group by year(sale_addtime)) A 
        full join (select year(saleout_addtime) AS col2,saleout_amount =sum(convert(decimal(18,2),c.item_amount)) from x_saleout b left join x_saleoutitem c on c.item_saleout=b.saleout_code left join x_product d on d.pro_id=c.item_pro where 1=1 group by year(saleout_addtime)) B on A.sale_addtime = B.saleout_addtime