469,917 Members | 1,489 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

Help

18
for ex one table is there like charge ,fields are chargeid,chargename

chargeid's are having duplicates like chargeid
101
101
102
.......
1.I want to disply the colmns of chargeid's and no.of times like(in desc order)

chargeid no. of times
101 2
102 ----

2.I want to display only those chargeid's are maximum times repeated
Feb 8 '08 #1
5 748
amitpatel66
2,367 Expert 2GB
for ex one table is there like charge ,fields are chargeid,chargename

chargeid's are having duplicates like chargeid
101
101
102
.......
1.I want to disply the colmns of chargeid's and no.of times like(in desc order)

chargeid no. of times
101 2
102 ----

2.I want to display only those chargeid's are maximum times repeated
Could you please post what you have tried so far??
Feb 8 '08 #2
kiran83
18
Could you please post what you have tried so far??
select chargeid,count(*) from charges group by chargeid having count(*)>1 order by 2

this query displays chargeid's and corresponding number of times for the chargeid now i want to disply only maximum number of chargeid's list in this table (suppose 101 chargeid is maximum used in the table)

like

chargeid no. of times
101 1
101 2

(or)

chargename chargeid

101
101
Feb 8 '08 #3
deepuv04
227 Expert 100+
select chargeid,count(*) from charges group by chargeid having count(*)>1 order by 2

this query displays chargeid's and corresponding number of times for the chargeid now i want to disply only maximum number of chargeid's list in this table (suppose 101 chargeid is maximum used in the table)

like

chargeid no. of times
101 1
101 2

(or)

chargename chargeid

101
101

hi,
if you want to get only the maximum number of times repeated chargid then
use the following query

thanks

select top 1 chargeid,count(*) from charges group by chargeid having count(*)>1 order by 2 desc
Feb 8 '08 #4
kiran83
18
now i want to disply only the maximum no. of chargeid's list(individual list) like below ex:


ex:

chargeid chargename
101 ------- xxx
101 ------- yyy
101 -------- aaa
101 ------- kkk
Feb 9 '08 #5
deepuv04
227 Expert 100+
now i want to disply only the maximum no. of chargeid's list(individual list) like below ex:


ex:

chargeid chargename
101 ------- xxx
101 ------- yyy
101 -------- aaa
101 ------- kkk

SELECT charges.chargeid ,charges.chargename from charges INNER JOIN
( select top 1 chargeid,count(*) from charges group by chargeid having count(*)>1 order by 2 ) AS C1
on charges.chargId = c1.chargid
Feb 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Tom | last post: by
6 posts views Thread by wukexin | last post: by
3 posts views Thread by Colin J. Williams | last post: by
7 posts views Thread by Corepaul | last post: by
5 posts views Thread by Steve | last post: by
8 posts views Thread by Mark | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.