Home » SQL & PL/SQL » SQL & PL/SQL » Need SQL Help Please
Need SQL Help Please [message #200409] Mon, 30 October 2006 16:46 Go to next message
taylor99ss
Messages: 3
Registered: October 2006
Junior Member
i have these two select statements

select count(1.a), 2.b
from 1, 2
where table join
and date = 123456
and 1.a = x
group by 2.b

AND THE SECOND

select count(2.a), 2.b
from 1, 2
where "table join"
and date = 123456
group by 2.b

as you can hopefully see the selects are very similar except the first select has an additional where clause or filter on the column being counted.

any help bringing these two statements into one would be GREATLY appriciated.
Re: Need SQL Help Please [message #200415 is a reply to message #200409] Mon, 30 October 2006 18:08 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
try to give a proper example - what you have written would never even nearly run.

and t1.a = nvl(x, t1.a) 
Re: Need SQL Help Please [message #200567 is a reply to message #200415] Tue, 31 October 2006 06:45 Go to previous messageGo to next message
taylor99ss
Messages: 3
Registered: October 2006
Junior Member
sorry let me try this again.
I know this exact code wont run, i tried to replace the exact table and column names. sorry if its confusing

select count(table1.column1), table3.column1
from table 1, table3
where table1.column3 = table3.colunm3
and date = 123456
and table1.column1 = 1
group by table3.column1

AND THE SECOND

select count(table2.column1), table3.column1
from table 2, table3
where table2.column3 = table3.colunm3
and date = 123456
group by table3.column1

they are similar. but different. I need to figure out a way to get the count(table1.column1), count(table2.column1) and group by table3.column3 all in the same select.

thanks
Re: Need SQL Help Please [message #200585 is a reply to message #200409] Tue, 31 October 2006 07:38 Go to previous messageGo to next message
Cthulhu
Messages: 381
Registered: September 2006
Location: UK
Senior Member
select count(case when table1.column1 = 1 then 1 end), 
       count(table2.column1), 
       table3.column1
from table 1, table3
where table1.column3 = table3.colunm3
and date = 123456
group by table3.column1
Re: Need SQL Help Please [message #200632 is a reply to message #200585] Tue, 31 October 2006 10:40 Go to previous messageGo to next message
S.Rajaram
Messages: 1027
Registered: October 2006
Location: United Kingdom
Senior Member
what do you mean by similar ?

Do you mean to say that they both count the number of records. Agreed but if you see the join conditions your first query joins table1 and table3 and there is no mention of table2. Your second query joins table2 and table3 and there is no mention of table1. So they are entirely different. How do you expect these two to be merged into a single query ? My personal feeling is you are asking for impossible. I could be wrong. Also could you please tell me why do you want to merge into a single select ?

Anyways good luck.
Re: Need SQL Help Please [message #200642 is a reply to message #200585] Tue, 31 October 2006 11:31 Go to previous message
taylor99ss
Messages: 3
Registered: October 2006
Junior Member
Cthulhu,

Thank you VERY MUCH this is EXACTLY what i needed.
Previous Topic: Union Vs Union All
Next Topic: Drop Down List in MOD Pl/sql
Goto Forum:
  


Current Time: Sat Dec 03 09:57:31 CST 2016

Total time taken to generate the page: 0.09710 seconds