MAX日,所有列的顯着成果使用SQL Server 2012獲取基礎上的一個
我已經看到了關於該主題的幾個線程,但我不能找到一個涉及查詢多個連接。我無法在此數據庫上創建VIEW,因此需要連接。
查詢
SELECT
p.Price
,s.Type
,s.Symbol
, MAX(d.Date) Maxed
FROM AdventDW.dbo.FactPrices p
INNER JOIN dbo.DimSecurityMaster s
ON s.SecurityID = p.SecurityID
INNER JOIN dbo.DimDateTime d
ON
p.DateTimeKey = d.DateTimeKey
GROUP BY p.Price ,
s.Type ,
s.Symbol
ORDER BY s.Symbol
查詢工作,但並沒有產生明顯的效果。我正在使用Order by來驗證結果,但是一旦我開始工作,就不需要它了。我結果集看起來像這樣。
Price Type Symbol Maxed
10.57 bfus *bbkd 3/31/1989
10.77 bfus *bbkd 2/28/1990
100.74049 cbus 001397AA6 8/2/2005
100.8161 cbus 001397AA6 7/21/2005
的結果集我要的是
Price Type Symbol Maxed
10.77 bfus *bbkd 2/28/1990
100.74049 cbus 001397AA6 8/2/2005
這裏是一些其他StackOverflow的線程我試過,但不能用我特定的查詢得到牛逼工作
How can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?
SQL Selecting distinct rows from multiple columns based on max value in one column
此查詢達到期望的結果。在我將Order BY s.symbol更改爲ts.symbol時需要一個小編輯。謝謝。 –