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 |
nrajeshkumars
Starting Member
5 Posts |
Posted - 2014-02-20 : 23:34:09
|
SalesOrder SalesOrderID ItemID SalesAmount1 101 1001 104 1202 101 2002 103 2253 101 2003 102 2403 103 4504 101 1004 102 4804 103 4504 104 5605 105 666 ItemDetail ItemID CatID101 1102 2103 1104 2105 2“SalesOrder” table has order details and “ItemDetail” table has items detail. A select query is required to get all those item’s amount from SalesOrder table whose amount is greater than category 1 item’s (101,103) amountExpected Result SalesOrderID ItemID SalesAmount4 102 4804 104 5605 105 666Pls. help me in writing query to get the expected result.Thanks,Rajesh.N.Rajesh kumar |
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2014-02-21 : 00:02:24
|
SELECT SalesOrderId,S.ItemId,S.SalesAmount FROM(SELECT S.ItemId,max(S.SalesAmount)AS SalesAmount FROM @SalesOrder AS SINNER JOIN @ItemDetail AS ION S.ItemID = I.ItemIDWHERE I.CatId > 1 GROUP BY S.ItemId)xINNER JOIN @SalesOrder SON X.SalesAmount = S.SalesAmountVeera |
|
|
nrajeshkumars
Starting Member
5 Posts |
Posted - 2014-02-21 : 00:08:13
|
Veera,Thanks for the post.but the condition isNo hardcoding is allowed. TOP, IN, MAX and Except keywords are not allowed in query.N.Rajesh kumar |
|
|
|
|
|