我是SQL的新手,所以寻求一些帮助。 继承我的代码
Select
MITARBEITER_NR "ID",
DAUER "Duration",
datum "Date"
From
Vtsbreak
Where DATUM >= TO_DATE('2017/04/01', 'yyyy/mm/dd') AND DATUM <= TO_DATE('2017/05/27','yyyy/mm/dd')
order by datum
这是我的数据
ID Duration Date
443 60 03/04/2017
412 10 03/04/2017
399 100 04/04/2017
374 10 04/04/2017
374 10 04/04/2017
376 120 04/04/2017
456 300 04/04/2017
372 120 04/04/2017
443 60 04/04/2017
446 300 04/04/2017
427 60 04/04/2017
403 420 04/04/2017
我要做的是返回ID代码,日期,该日期的持续时间总和 我尝试过使用group但是只返回一个id为374的案例,时间为04/04/2017,值为10而不是20
有什么建议吗?
答案 0 :(得分:1)
你想要一个GROUP BY
。按照您使用的语法(但绝对不是MySQL),您可以执行以下操作:
select MITARBEITER_NR as id,
to_char(datum, 'YYYY-MM-DD') as yyyymmdd,
sum(dauer) as duration
from Vtsbreak
where datum >= DATE '2017-04-01' and
datum < DATE '2017-05-28'
group by id, to_char(datum, 'YYYY-MM-DD')
order by yyyymmdd;
答案 1 :(得分:0)
排序
Select
MITARBEITER_NR "ID",
sum(DAUER) "Duration",
datum "Date"
From
Vtsbreak
Where DATUM >= TO_DATE('2017/04/01', 'yyyy/mm/dd') AND DATUM <= TO_DATE('2017/05/27','yyyy/mm/dd')
group by MITARBEITER_NR, datum;
order by datum