|
-
Jan 18th, 2012, 11:49 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Sub-select
Hi,
I will need a hint on how to write a mssql query.
I will like to run two SQL query as one query.
1) Select * from xxx where yyy=000 from zzzz
2) select user , sum(aaa+bbb) from xxx where hhh=4
i would like to run the second query on the result i will get from query 1. I'm not sure which function to use.
Thx
-
Jan 18th, 2012, 01:19 PM
#2
Re: Sub-select
Hello,
If you're still looking for responses, please post a script that will
a) Create necessary table structure.
b) Insert some data into these table structures.
c) Desired output from this data. How does the output look like?
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jan 18th, 2012, 01:22 PM
#3
Re: Sub-select
Like this:
select user , sum(aaa+bbb)
from (Select * from xxx where yyy=000 from zzzz) AS www
where hhh=4
-
Jan 19th, 2012, 01:08 AM
#4
Thread Starter
Frenzied Member
Re: Sub-select
Hi,
it's giving me an error on the second from and as
SELECT user, sum((a,b))
group by user
from
(select * FROM xxxxkmain where net>0 ) as aaa
thx
Last edited by met0555; Jan 19th, 2012 at 10:03 AM.
-
Jan 19th, 2012, 12:11 PM
#5
Re: Sub-select
The group by should be after the "from", like this:
Code:
SELECT user, sum((a,b))
from (select * FROM xxxxkmain where net>0 ) as aaa
group by user
-
Jan 21st, 2012, 10:48 PM
#6
Thread Starter
Frenzied Member
Re: Sub-select
Thx, for the sample, my code is now working as expected
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
|