2016-02-26 48 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;