Foxtable(狐表)用户栏目专家坐堂 → SQL的select语句修改


  共有2629人关注过本帖树形打印复制链接

主题:SQL的select语句修改

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/28 15:02:00 [显示全部帖子]

代码不要这样写啊,比如

 

Select YEAR(年) As 年,  sum(收入) as 收入, sum(支出) as 支出 f rom

 

(Select sys_user, 日期 as 年, 金额 as 收入, 0 as 支出 f rom {其他收入} U nion all

Select sys_user, 购买_日期, 0, 购买_金额 f rom {母猪基本信息})
 
as a where sys_user = '张三' group by year(年) order by year(年) 

 


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/28 15:34:00 [显示全部帖子]

 "Select YEAR(年),  sum(收入) as 收入, sum(支出) as 支出 f rom " _
 & "(Select sys_user, 销售_日期 as 年, 销售_金额 as 收入, 0 as 支出 f rom {母猪基本信息} u nion all " _
 & "Select sys_user, 销售_日期, 销售_金额, 0  f rom {公猪信息} u nion all " _
 & "Select sys_user, 销售_日期, 销售_金额, 0  f rom {肉猪信息} u nion all " _
 & "Select sys_user, 日期, 金额, 0  f rom {补贴项目}  u nion all " _
 & "Select sys_user, 日期, 金额, 0  f rom {其他收入}  u nion all " _
 & "Select sys_user, 购买_日期, 0, 购买_金额 f rom {母猪基本信息} u nion all " _
 & "Select sys_user, 购买_日期, 0, 购买_金额 f rom {公猪信息} u nion all " _
 & "Select sys_user, 购买_日期, 0, 购买_金额 f rom {肉猪信息} u nion all " _
 & "Select sys_user, 日期, 0,  饲料量_总金额 f rom {饲料采购} u nion all " _
 & "Select sys_user, 日期, 0,  总金额  f rom {疫苗采购}  u nion all " _
 & "Select sys_user, 日期, 0,  总金额  f rom {药品采购}  u nion all " _
 & "Select sys_user, 日期, 0,  总金额  f rom {易耗品采购}  u nion all " _
 & "Select sys_user, 日期, 0,  投保金额  f rom {保险费} u nion all " _
 & "Select sys_user, 日期, 0,  金额  f rom {水电费}  u nion all " _
 & "Select sys_user, 日期, 0,  金额  f rom {工资费用}  u nion all " _
 & "Select sys_user, 日期, 0,  支出金额  f rom {工程折旧费用} u nion all " _
 & "Select sys_user, 日期, 0,  金额  f rom {其他支出} ) " _
 & "As a where [sys_user] ='" & user.Name & "'  group by year(年) order by year(年) "

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/28 15:58:00 [显示全部帖子]

 

[此贴子已经被作者于2015/8/28 15:58:15编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/28 16:01:00 [显示全部帖子]

也行,但不能有空行

 

"Select YEAR(年),  sum(收入) as 收入, sum(支出) as 支出 f rom " & _
"(Select sys_user, 销售_日期 as 年, 销售_金额 as 收入, 0 as 支出 f rom {母猪基本信息} u nion all " & _
"Select sys_user, 销售_日期, 销售_金额, 0  f rom {公猪信息} u nion all " & _
"Select sys_user, 销售_日期, 销售_金额, 0  f rom {肉猪信息} u nion all " & _
"Select sys_user, 日期, 金额, 0  f rom {补贴项目}  u nion all " & _
"Select sys_user, 日期, 金额, 0  f rom {其他收入}  u nion all " & _
"Select sys_user, 购买_日期, 0, 购买_金额 f rom {母猪基本信息} u nion all " & _
"Select sys_user, 购买_日期, 0, 购买_金额 f rom {公猪信息} u nion all " & _
"Select sys_user, 购买_日期, 0, 购买_金额 f rom {肉猪信息} u nion all " & _
"Select sys_user, 日期, 0,  饲料量_总金额 f rom {饲料采购} u nion all " & _
"Select sys_user, 日期, 0,  总金额  f rom {疫苗采购}  u nion all " & _
"Select sys_user, 日期, 0,  总金额  f rom {药品采购}  u nion all " & _
"Select sys_user, 日期, 0,  总金额  f rom {易耗品采购}  u nion all " & _
"Select sys_user, 日期, 0,  投保金额  f rom {保险费} u nion all " & _
"Select sys_user, 日期, 0,  金额  f rom {水电费}  u nion all " & _
"Select sys_user, 日期, 0,  金额  f rom {工资费用}  u nion all " & _
"Select sys_user, 日期, 0,  支出金额  f rom {工程折旧费用} u nion all " & _
"Select sys_user, 日期, 0,  金额  f rom {其他支出} ) " & _
"As a where [sys_user] ='" & user.Name & "'  group by year(年) order by year(年) "

 


 回到顶部