我的桌子如下
DATE | JOB_ID |Name | Count
--------------------|-----------|-----------|--------
01-JAN-18 01:02:41 | JOB_1 | weight | 200
01-JAN-18 01:02:41 | JOB_1 | weight | 200
01-JAN-18 01:02:42 | JOB_1 | weight | 200
01-JAN-18 01:02:43 | JOB_1 | weight | 200
01-JAN-18 01:02:43 | JOB_1 | weight | 200
02-JAN-18 01:02:44 | JOB_2 | weight | 200
02-JAN-18 01:02:45 | JOB_2 | weight | 200
01-JAN-18 01:03:16 | JOB_1 | baseball | 192
01-JAN-18 01:11:15 | JOB_1 | hanescom | 37
01-JAN-18 01:11:15 | JOB_1 | hanescom | 200
01-JAN-18 01:11:16 | JOB_1 | hanescom | 200
01-JAN-18 01:11:17 | JOB_1 | hanescom | 200
01-JAN-18 01:11:17 | JOB_1 | hanescom | 200
01-JAN-18 01:11:18 | JOB_1 | hanescom | 200
03-JAN-18 01:11:25 | JOB_3 | hanescom | 200
03-JAN-18 01:11:26 | JOB_3 | hanescom | 200
03-JAN-18 01:11:26 | JOB_3 | hanescom | 200
01-JAN-18 01:11:27 | JOB_1 | hanescom | 189
01-JAN-18 01:11:28 | JOB_1 | wwbundle | 200
01-JAN-18 01:11:29 | JOB_1 | wwbundle | 200
01-JAN-18 01:11:29 | JOB_1 | wwbundle | 200
01-JAN-18 01:11:30 | JOB_1 | wwbundle | 200
我想得到低于结果的结果,
DATE | JOB_ID |Name | sum(Count)
--------------------|-----------|-----------|--------
01-JAN-18 |JOB_1 |weight | 1000
02-JAN-18 |JOB_2 |weight | 400
01-JAN-18 |JOB_1 |baseball | 192
01-JAN-18 |JOB_1 |hanescom | 1226
03-JAN-18 |JOB_3 |hanescom | 600
01-JAN-18 |JOB_1 |wwbundle | 800
答案 0 :(得分:3)
只不过是一个简单的分组,如下所示:
SELECT trunc("date") as "Date", JOB_ID as "Job ID",
Name as "Name", sum("count") as "Sum of Counts"
FROM tab
GROUP BY trunc("date"), JOB_ID, Name;
其中date
和count
是保留的关键字,应用双引号引起来。
答案 1 :(得分:-4)
您可以使用sql的日期格式方法获得所需的结果
选择DATE_FORMAT(date,'%Y-%m-%d')作为date_column,JOB_ID,名称,sum(“ count”) 从选项卡 GROUP BY date_column,JOB_ID,名称;