|
-
Sep 5th, 2012, 05:39 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] multiple select queries
Hi,
I'm running into a SQL select query problem. I know how to combine two select queries but now i need to combine 3 more queries.
Normally this is how i do it with two queries
Code:
SELECT color as 'COLOUR', sum((A-B) as 'FIRST' from (select * FROM xx Where user=admin and country=Canada) as aaa group by colour
But now i don't know how to merge all these select queries.
This is my main SQL query
Code:
Select * from xx where user=admin and country=Canada
And then from the result of my main SQL query i would like to run the next queries to calculate my final result "final" and group them by colour . Here i have no idea how to do it.
Code:
(select (A-B) as first where car=yes
+ select (C-D) as second where car=no
- select (E) as thrid where car=maybe) as final and group by COLOR
Any help will be appreciated.
Thank You
-
Sep 6th, 2012, 08:17 AM
#2
Re: multiple select queries
I'm afraid it's pretty much impossibleto understand what you're trying to do from the information you're given here. The first two code blocks aren't valid sql and would not run (the second one might but only if you had columns called admin and canada which I doubt) and the third code block doesn't make any sense at all to me.
Could you provide some sample data and what you'd expect the output to be? If we can understand what you're trying to achieve we can probably give you an answer.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Sep 6th, 2012, 09:33 PM
#3
Thread Starter
Frenzied Member
Re: multiple select queries
Not all of them are valid SQL queries, it's jsut to give you an idea what i want. But i found the solution for it.
Code:
SELECT COLOR,
SUM(
CASE WHEN car = 'yes' THEN ISNULL(A, 0)- ISNULL(B, 0)
WHEN car = 'no' THEN ISNULL(C, 0)- ISNULL(D, 0)
WHEN car = 'maybe' THEN ISNULL(E, 0) * -1
ELSE 0
END
)
FROM xx
WHERE user='admin' AND country='Canada'
GROUP BY COLOR
http://forums.asp.net/p/1840767/5136...25674905721254
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|