CREATE table #MyTabel (
ClassNo varchar(4)
, StudentName varchar(16)
)
;
insert into #MyTabel(ClassNo, StudentName) Values
('A001', 'John')
,('A001', 'John')
,('A002', 'John')
,('A002', 'John')
,('A002', 'Tom')
,('A003', 'John')
,('A003', 'John')
,('A003', 'Tom')
,('A003', 'Tom')
;
select * from #MyTabel;
select T2.ClassNo, 'could be better' as Comment
from
(
select distinct ClassNo, StudentName
from #MyTabel
) T2
group by T2.ClassNo
having count(1)>1
;
select ClassNo, 'much better' as Comment
from #MyTabel
group by ClassNo
having count(distinct StudentName)>1
;
drop table #MyTabel;
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.