Prepare for your Next Interview
This is a discussion on Group by and order by within the SQL Server forums, part of the Databases category; Hi friends, i am executing this query in sql server 2005 select * from users where (primaryemail like 'brijesh%@efextra.com') order by firstname and it's working well.but when ...
|
|||
|
Group by and order by
Hi friends, i am executing this query in sql server 2005 select * from users where (primaryemail like 'brijesh%@efextra.com') order by firstname and it's working well.but when i tried this one select * from users where (primaryemail like 'brijesh%@efextra.com') group by firstname it's shows me error, why? i am not getting the reason
![]()
__________________
Brijesh Jain brijesh.tester@yahoo.co.in http://softwaretestingexpertise.blogspot.com |
| Sponsored Links |
|
|||
|
Re: Group by and order by
Hi Brijesh,
To use a Group BY clause, you would need to have atleast one aggregate function in the Select Clause. Aggregate function like Count(*), Sum, Avg etc. All other columns excepting the one with the Aggregate function, would need to be part of the GroupBy clause. Example. Select METHOD_NAME, Count(*), ROUND(AVG(LAST_CALL_DURATION)/1000,3), SERVICE_NAME, RESPONSE_STATUS From SGC.GATE_QUEUE where SYSTEM_NAME in ('CCTOOL', 'FALLOUT_HANDLING_TOOL') -- application of interest and date_modified >= to_date('10/03/2007 06:24 AM', 'MM/DD/YYYY HH:MI AM') and date_modified <= to_date('10/03/2007 07:45 AM', 'MM/DD/YYYY HH:MI AM') and METHOD_NAME = 'getPort25' Group By SERVICE_NAME, METHOD_NAME, RESPONSE_STATUS Cheers...
__________________
Regards, V.Umesh Krishnan QA Consultant |
|
|||
|
Re: Group by and order by
Quote:
I got my answer.It's not required to use a Group BY clause, you would need to have atleast one aggregate function in the Select Clause. But the case is that, the column name which you are using in select should be either in group by statement or in aggregate function. ![]()
__________________
Brijesh Jain brijesh.tester@yahoo.co.in http://softwaretestingexpertise.blogspot.com |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sales order conversion | syedrafi123 | Oracle Apps | 5 | 11-22-2007 08:20 AM |
| I am not able to see / add the Sales order number | ritz206 | Oracle Apps | 1 | 08-10-2007 04:11 PM |
| difference b/w "group by" and "order by" ? | jainbrijesh | SQL | 9 | 07-07-2007 01:40 AM |
| How to make a P.O (Purchase Order) | javad.mohammed | Data Warehousing | 0 | 04-20-2007 05:16 AM |
| Is Order by on Rownum Possible | Bessie | SQL | 1 | 08-17-2006 09:35 AM |