简体   繁体   English

SQL语句组? 或总和?

[英]SQL statement group? or sum?

im new to SQL so looking for some assistance. 我是SQL的新手,所以需要一些帮助。 heres my code 这是我的代码

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

this is my data 这是我的数据

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

what I am trying to do is return the ID code, Date, sum of duration for that date I have tried using group but just returns one case of id 374 for 04/04/2017 with a value of 10 instead of 20 我想做的是返回ID码,日期,我尝试使用组的该日期的持续时间总和,但只返回ID 374 for 04/04/2017的一种情况,其值为10而不是20

any suggestions please? 有什么建议吗?

You want a GROUP BY . 您想要GROUP BY Following the syntax you are using (but definitely not MySQL), you can do something like this: 按照您使用的语法(但绝对不是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;

sorted it 排序

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM