Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have got below out put by this query

SQL
select MAX(N_Days) days,COUNT(N_Days) count from tbl_setting
where N_flag=0
group by N_Days

Out Put is like
SQL
days    	count
7	        304
14	        7
30	        1
45	        5
60	        1
90	        8


Now i need only one value of days column that is having more count like in below format
SQL
days
7
Posted
Updated 30-Mar-15 21:03pm
v3
Comments
Herman<T>.Instance 31-Mar-15 3:04am    
What do you mean with 'having more count like'? Please improve your question.

Hi,

Check this...



SQL
SELECT DAYS FROM from tbl_setting WHERE COUNT_Field = (SELECT MAX(COUNT_Field) from tbl_setting WHERE N_flag=0 )
--here COUNT_Field is field name which gives you counts as i am not sure about your correct field name.


Hope this will help you.


Cheers
 
Share this answer
 
Use top1 with order by,

You may try like this,
SQL
select top 1 MAX(N_Days) days,COUNT(N_Days) count from tbl_setting
where N_flag=0
group by N_Days
order by count desc 

It will provide o/p like,
SQL
Days          Count
7             304

[Edit2:] If you need single column you may try subquery,
SQL
select A.days from (
select top 1 MAX(N_Days) days,COUNT(N_Days) count from tbl_setting
where N_flag=0
group by N_Days
order by count desc
) as A 

Output:
SQL
days
7

Hope this may helpful to you.
 
Share this answer
 
v4
Comments
Santosh K. Tripathi 31-Mar-15 3:19am    
correct.
Rajesh waran 31-Mar-15 3:20am    
Thank you.
Try this,

SQL
select top 1 max(N_Days)days From tbl_setting where N_flag=0 group by N_Days order by  COUNT(N_Days) 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