Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jtw5074
Starting Member
4 Posts |
Posted - 2013-06-28 : 12:33:21
|
I am trying to create a query that will return the results in which the Average Sale Price (ASP) from 2013 is lower than the ASP from 2012. My attempt is below. Any suggestions? Thanks very much. SELECT [Year] ,[SKU Number] ,[Country] ,[Units] ,[Sales] ,[ASP] FROM [Wirt].[dbo].[Basal_Media_2]ORDER BY [SKU Number] ,[Country] ,[Year]WHERE [ASP] for [YEAR] = '2012' > [ASP] for [YEAR] = '2013' |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-28 : 12:40:00
|
[code]SELECT[Year],[SKU Number],[Country],[Units],[Sales],m.[ASP] FROM [Wirt].[dbo].[Basal_Media_2] mCROSS APPLY (SELECT [ASP] FROM [Wirt].[dbo].[Basal_Media_2] WHERE [SKU Number] = m.[SKU Number] AND [Country] = m.[Country] AND [Year] = m.[Year] -1 )m1WHERE m.[ASP] < m1.[ASP]AND m.[Year] = 2013ORDER BY [SKU Number],[Country],[Year][/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
jtw5074
Starting Member
4 Posts |
Posted - 2013-06-28 : 13:00:01
|
Thank you sir, that did the trick. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-28 : 13:22:02
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|