Home » RDBMS Server » Server Administration » SQL Command need help!
SQL Command need help! [message #371000] Thu, 03 August 2000 11:58 Go to next message
Jovi
Messages: 1
Registered: August 2000
Junior Member
SQL Server 7.0
Table
ID Subject
========
1 A
2 C
3 A
4 B
5 D
6 B

How to Select Like this:
(Order By ID)

ID Subject Count
=============
1 A 2
2 C 1
4 B 2
5 D 1
Re: SQL Command need help! [message #371003 is a reply to message #371000] Fri, 04 August 2000 11:05 Go to previous messageGo to next message
Geraldo Viana de Paula Ju
Messages: 8
Registered: August 2000
Junior Member
I'm not sure if i've understood what exactly you want, my english is poor, so. but I guess:
"select id, subject, count(*) from table_name group by id, subject order by id"
Re: SQL Command need help! [message #371007 is a reply to message #371000] Sat, 05 August 2000 16:31 Go to previous message
Vjeko
Messages: 15
Registered: August 2000
Junior Member
I think this statement will work fine:
SELECT t1.Id,t1.Subject,t2.number_of_subjects
FROM Table t1,(select t.Subject,count(*) number_of_subjects from Table t group by t.Subject) t2
WHERE t1.Subject=t2.Subject and t1.Id in (select min(id) from Table group by Subject)
ORDER BY t1.Id;
Previous Topic: Re: Copying database by FTP method
Next Topic: Re: Ocp Exam
Goto Forum:
  


Current Time: Sun Dec 22 06:51:14 CST 2024