I would like to select distinct on some column, and get other information from other column (not distinct):
SELECT A,B,DISTINCT C FROM TABLE
I know that SQL accept only distinct just after "select"
Please help me!
Table "TLQuyDoi"
cifno ten DCQuyDoi
1 a 10
1 b 10
2 s 9
I like to get only distinct on (cifno and DCQuyDoi) , besides get the value of "Ten"
The resuls I hope like this
cifno ten DCQuyDoi
1 a 10
2 s 9
Here is my code
create table #KetQua (cifno varchar(10),SumDCQuyDoi float)
Insert into #KetQua
Select cifno,sum(DCQuyDoi)
From TLQuyDoi t
Group by cifno
Having sum(DCQuyDoi) >= @GiaTri
Order by cifno,sum(DCQuyDoi)
Select distinct k.cifno,t.ten,k.SumDCQuyDoi
From #KetQua k,TLQuyDoi t
Where k.cifno=t.cifno Order by k.SumDCQuyDoi desc,k.cifno asc
drop table #KetQua