2016-09-14 77 views
-3

Data tableSQL腳本表

選擇最後一欄我要選擇最後

+0

請看看這個鏈接,看你如何改善的問題: https://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/ – TheGameiswar

+0

很好,謝謝 –

回答

0

你不應該在圖像數據給出的文本。不管怎麼說 試試這個:

select * 
from data_table 
qualify() row_number()over(partition by computerName order by timestamp desc)=1 

或本:

select * 
from data_table 
where (computerName,timestamp) 
in 
(select computerName,max(timestamp) 
from data_table 
group by 1) 
0

使用分區中

SELECT 
    ComputerName, 
    CodeNumber, 
    TimeStamp 
FROM 
(
    SELECT 
     ComputerName, 
     CodeNumber, 
     TimeStamp, 
     ROW_NUMBER() OVER (PARTITION BY t.ComputerName ORDER BY t.TimeStamp DESC) AS [Rank] 
    FROM @data t 
) AS [sub] 
where [sub].[Rank] = 1