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时需要一个小编辑。谢谢。 –