以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  sql select 语句的更改  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=73881)

--  作者:阿福
--  发布时间:2015/8/28 11:41:00
--  sql select 语句的更改
麻烦老师,帮我改一下!

cmd.CommandText = "select 年, 销售_母猪 + 销售_公猪 + 销售_肉猪 + 补贴项目 + 其他收入 as 合计 f rom " & _
"(Select YEAR(销售_日期) As 年, sum(销售_母猪) As 销售_母猪, sum(销售_公猪) As 销售_公猪, sum(销售_肉猪) As 销售_肉猪, sum(补贴项目) As 补贴项目, sum(其他收入) As 其他收入 f rom" & _
"(Select 销售_日期, 销售_金额 As 销售_母猪, 0 As 销售_公猪, 0 As 销售_肉猪, 0 As 补贴项目, 0 As 其他收入 f rom {母猪基本信息} where [sys_user]=\'" & user.Name & "\' u nion all " & _
"Select 销售_日期, 0, 销售_金额 As 销售_公猪, 0, 0, 0 f rom {公猪信息} where [sys_user]=\'" & user.Name & "\' u nion all " & _
"Select 销售_日期, 0, 0, 销售_金额 As 销售_肉猪, 0, 0 f rom {肉猪信息} where [sys_user]=\'" & user.Name & "\' u nion all " & _
"Select 日期, 0, 0, 0, 金额 As 补贴项目, 0 f rom {补贴项目} where [sys_user]=\'" & user.Name & "\' u nion all " & _
"Select 日期, 0, 0, 0, 0,金额 As 其他收入 f rom {其他收入} where [sys_user]=\'" & user.Name & "\') as b) " & _
"As a  group by 年  order by year 年  " 



[此贴子已经被作者于2015/8/28 11:48:53编辑过]

--  作者:大红袍
--  发布时间:2015/8/28 11:46:00
--  

 

Select YEAR(销售_日期) As 年,   sum(销售_金额) f rom


(Se lect 销售_日期, 销售_金额 f rom {母猪基本信息} u nion all


Se lect 销售_日期, 销售_金额  f rom {公猪信息} u nion all


Sel ect 销售_日期, 销售_金额  f rom {肉猪信息} u nion all


Sel ect 日期 as 销售_日期 , 金额 f rom {补贴项目} u nion all


Sel ect 日期 as 销售_日期 , 金额 f rom {其他收入})


As a group by year(销售_日期) order by year(销售_日期)


--  作者:阿福
--  发布时间:2015/8/28 12:01:00
--  
谢谢老师,原来我把它复杂了!