sql server - SQL - Comparing Multiple Rows in Query -
i have pricing table retail software holds upc item, property code (i.e. "regular_price, promo_price"), , price.
example table:
400000320243 regular_price 80 400000320243 promo_price 80 400000320250 regular_price 50 400000320250 promo_price 40
i trying write query find promo_price = regular_price upcs , output list of upcs status holds.
i cannot figure out how write in sql. using sql server 2008 r2.
attempted pseudo code:
for each upc: if upc.regular_price = upc.promo_price: print upc
you bunch of ways. 1 way create 2 sets, 1 upcs , regular prices, other upcs , promo prices, , bring together 2 sets, this:
select r.upc, r.price (select upc, cost t propertycode = 'regular_price') r inner bring together (select upc, cost t propertycode = 'promo_price') p on r.upc = p.upc , r.price = p.price
you can seek on sqlfiddle.
sql sql-server sql-server-2008-r2
No comments:
Post a Comment