2012-03-16 84 views
1

是否可以從此列表中檢索2個隨機數據?每次當我執行T-sql代碼時,它總是應該檢索具有不同數據的2行。檢索隨機數據

CREATE TABLE Data 
( 
    StartTime VARCHAR(5), 
    EndTime VARCHAR(5), 
) 
GO 

INSERT INTO Data(StartTime,EndTime) 
SELECT '10:00','12:00' UNION ALL 
SELECT '13:30','16:00' UNION ALL 
SELECT '14:00','15:00' UNION ALL 
GO 

// Fullmetaloby

+0

http://stackoverflow.com/questions/19412/how-to-request-a-random-row-in-sql 只是給限制2 – 2012-03-16 09:46:12

回答

6
SELECT TOP 2 StartTime, EndTime FROM Data 
ORDER BY NEWID()