| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.misc -> Re: same statement, different filter condition
Michel Cadot wrote:
> <pankaj_wolfhunter_at_yahoo.co.in> a écrit dans le message de news: 1162482743.167751.299420_at_k70g2000cwa.googlegroups.com...
> > SELECT > BADGE, > SUM(case when quote in (1,2,3,4) > then link > else 0 > end > ) col1, > SUM(case when quote in (5,6) > then link > else 0 > end > ) col2 > FROM ( > SELECT tab1.quote, tab2.badge, COUNT (DISTINCT tab2.link) link > FROM table1 tab1, > table2 tab2 > WHERE tab1.ttdate = tab2.ttdate > AND tab1.symbol = tab2.symbol > AND tab1.equote IN (1, 2, 3, 4, 5, 6) > GROUP BY tab1.quote, tab2.badge > ) > GROUP BY BADGE > / > > Regards > Michel Cadot
Thanks for the help
But Michael, there's something missing.
let me explain:
We have branches who have different BADGE nos.
Say firm "A" has 6 different badges. So I want a "sum of number of link
for firm A"
i.e one single output for this firm "A" and so on for all others
Your query would give me 6 different result for the same firm "A" grouped on BADGE.
My query can be presented with "branch" as:
SELECT SUM(case when quote in (1,2,3,4)
then link
else 0
end
) col1,
SUM(case when quote in (5,6)
then link
else 0
end
) col2
FROM (
SELECT tab1.branch, tab1.quote, tab2.badge, COUNT (DISTINCT
tab2.link) link
FROM table1 tab1,
table2 tab2
WHERE tab1.ttdate = tab2.ttdate
AND tab1.symbol = tab2.symbol
AND tab1.equote IN (1, 2, 3, 4, 5, 6)
GROUP BY tab1.branch, tab1.quote, tab2.badge
)
Something like (for COL1):
SELECT SUM(LINK) COL1
FROM (
SELECT TAB1.BRANCH, TAB2.BADGE, COUNT(DISTINCT TAB2.LINK) LINK
FROM TABLE1 TAB1,
TABLE2 TAB2
WHERE TAB1.SYMBOL = TAB2.SYMBOL
AND TAB2.QUOTE IN (1, 2, 3, 4)
AND TAB1.BRANCH = 'A' -- THIS
IS TO TEST FOR ONE BRANCH
GROUP BY TAB1.BRANCH, TAB2.BADGE
);
Output: 181
Sorry for not mentioning this before. Received on Thu Nov 02 2006 - 11:53:16 CST
![]() |
![]() |