Oracle SQL Developer:基于另一列的值求和行数
归来 --仅对2016年感兴趣Oracle SQL Developer:基于另一列的值求和行数,oracle,Oracle,归来 --仅对2016年感兴趣 Trans. ID QTY TOOL Date 1 20 A2 2015 2 20 A2 2016 3 20 A2 2016 4 20 A3 2015 5 20 A3 2016 6
Trans. ID QTY TOOL Date
1 20 A2 2015
2 20 A2 2016
3 20 A2 2016
4 20 A3 2015
5 20 A3 2016
6 20 A3 2016
7 20 C 2016
8 20 C 2016
9 20 C 2016
10 20 C 2016
我对个人身份证不感兴趣。只是更感兴趣的总数。
请注意,我也对使用以字母A开头的工具获取数据感兴趣,因为实际的表有一堆工具
我很难弄明白如何把WHERE语句和其他东西放在哪里。我在另一个线程中阅读,以使用distincts
Tool Total
A2 40
A3 40
如果在子查询中执行distinct,则将删除其中一行的ID为2和3。然而,从您的预期输出来看,您希望将两者相加 另外,日期列是什么数据类型?如果是日期或时间戳,那么我想这就是你想要的:
select Tool, sum(QTY)
from
(select distinct Tool, ID, QTY from "table")
where Tool like 'A%'
AND Date like '2016%'
group by PROCESS_EQP_ID
什么是
ID
,什么是PROCESS\u EQP\u ID
,为什么有嵌套的select?
select tool, sum(qty)
from "table"
where tool like 'A%'
and to_char(dt, 'yyyy') = '2016' -- note that I've renamed the date column as `date` is a reserved word in Oracle.
group by tool;