sql语句里top和distinct一起用

例如:Pubs數據庫下的authors表
select   distinct   top   4   au_lname,au_fname   from   authors
order   by   au_fname
結果:
au_lname                                                                   au_fname                          
----------------------------------------   --------------------  
Bennet                                                                       Abraham
Yokomoto                                                                   Akiko
Ringer                                                                       Albert
Dull                                                                           Ann

 

 

SELECT    distinct TOP 10 A.ID  ,  CTX_ID, TELE_NUM, START_TIME, TIME_SPAN, CALLED, BASE_FEE, EXA_FEE, SERVICE_FEE, SUM_FEE
 FROM [dbo].[HightSpeedView]  AS A  INNER JOIN
( SELECT  * FROM [dbo].[fn_test](30)) AS BB  ON (  A.TELE_NUM = BB.TELE or
 A.TELE_NUM=BB.SMALL_TELE)  WHERE (1=1)
    AND  CTX_ID =4596 AND(
tele_num IN (SELECT TELE FROM  telenumbs where id IN
(SELECT TELE_ID FROM Hotelsettings where Department= N'10楼' AND
 Hotel_id =30 ) ) or tele_num in (select small_tele from  telenumbs
where id in (select tele_id from Hotelsettings where Department= N'10楼' 
AND  Hotel_id = 30  ) ) ) AND START_TIME>='2005-01-01 00:00:00 '
 AND START_TIME<='2011-01-01 00:00:00 ' ORDER BY A.ID DESC

你可能感兴趣的:(distinct)