By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,919 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,919 IT Pros & Developers. It's quick & easy.

2 group by in a single query

P: n/a
Jai
Say the following are the columns of a table
A B C D E F

Can a aggregate function like sum be applied to A like sum(a) and then
order by b and c similarly aggregate function on d and group by e and
f using a single query...
Regards,
Jai
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I'm not sure why you think you need two GROUP BYs. What do you expect to be
the difference between GROUP BY x followed by GROUP BY y rather than just
GROUP BY y? You can of course nest GROUP BY queries using a derived table in
the FROM clause. Nested aggregates can be used to count distinct values
within a group, in a similar way to COUNT(DISTINCT x):

SELECT A, COUNT(*)
FROM
(SELECT A,B
FROM foo
GROUP BY A,B) AS X
GROUP BY A

If you need more help, please post a CREATE TABLE statement for your table
and post some sample data as INSERT statements.

--
David Portas
------------
Please reply only to the newsgroup
--
Jul 20 '05 #2

P: n/a
Jai
Thanks a lot...
Ur example helped me a lot...
This was exactly what I was looking for...
Regards,
Jai

"David Portas" <RE****************************@acm.org> wrote in message news:<hu********************@giganews.com>...
I'm not sure why you think you need two GROUP BYs. What do you expect to be
the difference between GROUP BY x followed by GROUP BY y rather than just
GROUP BY y? You can of course nest GROUP BY queries using a derived table in
the FROM clause. Nested aggregates can be used to count distinct values
within a group, in a similar way to COUNT(DISTINCT x):

SELECT A, COUNT(*)
FROM
(SELECT A,B
FROM foo
GROUP BY A,B) AS X
GROUP BY A

If you need more help, please post a CREATE TABLE statement for your table
and post some sample data as INSERT statements.

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.