一统计sql语句
时间:2011-11-29
来源:互联网
SQL code
最后要查出来的字段是:
(查出所有用户的,没有的为0
姓名,部门 ,职位 ,总金额累计,到账金额累计,待发金额累计,本月总金额,本月到账金额,本月待发金额
--用户表 create table user_info ( u_id int primary key,--用户id u_name varchar2(20),--姓名 Department_id int ,--部门id Position_id int ,--职位id ) --到账记录表 create table user_yes_info ( u_id int , fee float,--金额 theMonth varchar(10)--月份 ) --待发记录表 create table user_waiting_info ( u_id int , fee float,--金额 theMonth varchar(10)--月份 ) --部门表 create table Department_info ( Department_id int primary key , Department_name varchar2(50) ) --职位表 create table Position_info ( Position_id int primary key , Position_name varchar2(50) )
最后要查出来的字段是:
(查出所有用户的,没有的为0
姓名,部门 ,职位 ,总金额累计,到账金额累计,待发金额累计,本月总金额,本月到账金额,本月待发金额
作者: liuxiulian 发布时间: 2011-11-29
SQL code
select ui.u_name, (select Department_name from Department_info where Department_id=ui.Department_id) as Department_name, (select Position_name from Position_info where Position_id=ui.Position_id) as Position_name, (select sum(fee) from user_yes_info where u_id=ui.u_id)+(select sum(fee) from user_waiting_info where u_id=ui.u_id) as sum_fee, (select sum(fee) from user_yes_info where u_id=ui.u_id) as yes_fee, (select sum(fee) from user_waiting_info where u_id=ui.u_id) as waiting_fee, (select sum(fee) from user_yes_info where u_id=ui.u_id and theMonth='11')+(select sum(fee) from user_waiting_info where u_id=ui.u_id and theMonth='11') as thismonth_sum_fee, (select sum(fee) from user_yes_info where u_id=ui.u_id and theMonth='11') as thismonth_yes_fee, (select sum(fee) from user_waiting_info where u_id=ui.u_id and theMonth='11') as thismonth_waiting_fee, from user_info ui
作者: lxpbs8851 发布时间: 2011-11-29
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28