|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
SQL语句:
select * from
(select (case f.客户编号 when null then e.客户编号 else f.客户编号 end )as 客户编号,(case f.客户编号 when null then '无此人'else ltrim(rtrim(ltrim(rtrim(f.姓名))+' '+ltrim(rtrim(f.英文姓名))))end) as 客户姓名,f.会员号码,f.会员,(case e.总买入 when null then 0 else e.总买入 end)as 总买入,(case e.总卖出 when null then 0 else e.总卖出 end) as 总卖出,(case e.总额 when null then 0 else e.总额 end) as 总额 from customer as f full join
(with x as
(select (case b.客户编号 when null then '999999' else b.客户编号 end) as 客户编号,sum(a.成交价) as 总买入 from storeall a join auc_jtdj b on a.拍卖会id=b.拍卖会id and a.竞投牌号=b.竞投牌号 where (charindex('已结算',upper(a.买家结算状况))>0 or charindex('抵帐',upper(a.买家结算状况))>0) and a.拍卖会id in (58,57,56) group by b.客户编号),
y as
(select(case h.委托方编号 when null then '999999' else h.委托方编号 end) as 委托方编号,sum(a.成交价) as 总卖出 from storeall a join contract h on a.拍卖会id=h.拍卖会id and a.合同编号=h.合同编号 where (charindex('已结算',upper(a.买家结算状况))>0 or charindex('抵帐',upper(a.买家结算状况))>0) and a.拍卖会id in (58,57,56) group by h.委托方编号)
select(case x.客户编号 when null then y.委托方编号 else x.客户编号 end) as 客户编号,(case x.总买入 when null then 0 else x.总买入 end) as 总买入,(case y.总卖出 when null then 0 else y.总卖出 end)as 总卖出,(case x.总买入 when null then 0 else x.总买入 end)+(case y.总卖出 when null then 0 else y.总卖出 end ) as 总额 from x full join y on x.客户编号= y.委托方编号)
as e on f.客户编号=e.客户编号)
where 会员>0 or 总额>10000 order by 总额 desc
总是提示:
Msg 156, Level 15, State 1, Line 3
关键字 'with' 附近有语法错误。
Msg 102, Level 15, State 1, Line 7
')' 附近有语法错误。
急求原因,在线等。
|
|