由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 怎么写这个Query,谢谢
相关主题
SQLPASS Monthly Meeting(FEB 2014) and Free Session: Working with XML in SQL ServerQuestions on SQL
[转载] Can anyone interpret this simple SQL?A sql question
Help on Oracle Querysql面试题目求指点
怎么写个query 把输出变成横排.一个SQL query的问题
新手学数据库一个简单题求助[转载] question about SQL in Access
誰來幫我開來開悄? Interesting SQL queryparameterized queries with no inputs
包子请教queryA SQL query never stop running is bothering me: help needed (转载)
How to write this loop SQL query?SQL Server restore(transferred from other DB) error... HELP!
相关话题的讨论汇总
话题: decode话题: query话题: month话题: max
进入Database版参与讨论
1 (共1页)
B*****g
发帖数: 34098
1
一个table(employee),每个人(EMP_ID)每天(work_date as mm/dd/yy)都有一个工
作时间(work_hours). 现在要输出每个月的工作时间。
Emp_ID Jan Feb Mar ....... Dec
001 150 160 155 ........124
......
in oracle, only SQL, 不用考虑年份
谢谢
p******a
发帖数: 41
2
select emp_id, month(work_date) as month, sum(work_hours) as sumofworkhours
from employee
group by emp_id, month(work_date);

【在 B*****g 的大作中提到】
: 一个table(employee),每个人(EMP_ID)每天(work_date as mm/dd/yy)都有一个工
: 作时间(work_hours). 现在要输出每个月的工作时间。
: Emp_ID Jan Feb Mar ....... Dec
: 001 150 160 155 ........124
: ......
: in oracle, only SQL, 不用考虑年份
: 谢谢

B*****g
发帖数: 34098
3
谢谢,不过你这个输出应该是
Emp_ID month sum
001 Jan 150
001 Feb 160
.....
which is diffrent like what I want.

【在 p******a 的大作中提到】
: select emp_id, month(work_date) as month, sum(work_hours) as sumofworkhours
: from employee
: group by emp_id, month(work_date);

n********a
发帖数: 68
4
select emp_id,
max(decode(month, 'Jan', sumofworkhours, null)),
max(decode(month, 'Feb', sumofworkhours, null)),
max(decode(month, 'Mar', sumofworkhours, null)),
max(decode(month, 'Apr', sumofworkhours, null)),
max(decode(month, 'May', sumofworkhours, null)),
max(decode(month, 'Jun', sumofworkhours, null)),
max(decode(month, 'Jul', sumofworkhours, null)),
max(decode(month, 'Aug', sumofworkhours, null)),
max(decode(month, 'Sep', sumofworkhours, null)),
max(decode(month, 'Oct', sumofworkhours, nul

【在 B*****g 的大作中提到】
: 谢谢,不过你这个输出应该是
: Emp_ID month sum
: 001 Jan 150
: 001 Feb 160
: .....
: which is diffrent like what I want.

1 (共1页)
进入Database版参与讨论
相关主题
SQL Server restore(transferred from other DB) error... HELP!新手学数据库一个简单题求助
One sql question help!誰來幫我開來開悄? Interesting SQL query
How to write this query in Oracle?包子请教query
Help on Oracle QueryHow to write this loop SQL query?
SQLPASS Monthly Meeting(FEB 2014) and Free Session: Working with XML in SQL ServerQuestions on SQL
[转载] Can anyone interpret this simple SQL?A sql question
Help on Oracle Querysql面试题目求指点
怎么写个query 把输出变成横排.一个SQL query的问题
相关话题的讨论汇总
话题: decode话题: query话题: month话题: max