2016-02-26 50 views
0
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 

琛返回行 --Interested在2016年只有的Oracle SQL Developer:基于价值从另一列

Tool  Total 
A2   40 
A3   40 

林在个人IDS不感兴趣。只是更有兴趣的总数。 请注意,我也有兴趣使用专门用字母A开头的工具来抓取数据,因为实际的表格有一堆工具。

我很难弄清楚如何放置WHERE语句和其他东西。我读了另一个线程以使用区别。

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 
+0

什么是'ID',什么是'PROCESS_EQP_ID',为什么你有一个嵌套的选择呢? – Mat

回答

0

如果你在你的子查询的不同,你要淘汰与IDS 2行之一,并3。但是,从你期望的输出,你想既来概括。

此外,什么数据类型是日期列?如果它的日期或时间戳,那么我认为这是你追求的:

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;