Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
while executing below query i am getting error..

SQL
select t.d
from
(
select N_Days d , COUNT(N_Days) ds from Tbl_Setting
group by N_Days
)t
where t.ds=MAX(t.ds)


SQL
Msg 147, Level 15, State 1, Line 7
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.


How we could write this query in other style

Edit:2/ Reposted from Question - 1 [^], Question 2[^]
Posted
Updated 31-Mar-15 20:38pm
v4
Comments
Manoj Kumar Choubey 1-Apr-15 2:57am    
Try with group by and having
Member 11337367 1-Apr-15 3:07am    
could you show me how to write that..

1 solution

Try this:
SQL
select top 1 N_Days d, COUNT(N_Days) ds from Tbl_Setting group by N_Days order by ds desc;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900