Home SQL to identify rows with price changes, group by item
Reply: 0

SQL to identify rows with price changes, group by item

user1664
1#
user1664 Published in April 21, 2018, 3:24 pm

I have a table with thousands of entries for fruit items. Some fruit items sell right away, others get re-priced at a subsequent date at a lower price to clear inventory. Each item entry has a unique id / SKU but gets a new row ID when it's re-entered at a new price.

Original Table                  
ID  Date    UID Fruit   Variety Price
1   3/1/18  100100  Apple   Fiji    2.99
2   3/1/18  100101  Apple   Gala    3.99
3   3/1/18  100102  Apple   HoneyCrisp  4.99
4   3/1/18  100201  Orange  Navel   2.49
5   3/1/18  100202  Orange  Clementine  2.79
6   3/1/18  100301  Cherry  Bing    1.99
7   3/1/18  100302  Cherry  Black   2.29
8   3/8/18  100100  Apple   Fiji    2.69
9   3/8/18  100202  Orange  Clementine  2.15
10  3/15/18 100302  Cherry  Black   1.79
11  3/22/18 100102  Apple   HoneyCrisp  4.49
12  3/29/18 100201  Orange  Navel   2.19

And I am looking for output that lists the items that have had price changes, grouped by UID so that items that have re-priced show up in rows next to each other so its easy to view the comparison in the price change, like so:

Desired Results                 
ID  Date    UID Fruit   Variety Price
1   3/1/18  100100  Apple   Fiji    2.99
8   3/8/18  100100  Apple   Fiji    2.69
5   3/1/18  100202  Orange  Clementine  2.79
9   3/8/18  100202  Orange  Clementine  2.15
7   3/1/18  100302  Cherry  Black   2.29
10  3/15/18 100302  Cherry  Black   1.79
3   3/1/18  100102  Apple   HoneyCrisp  4.99
11  3/22/18 100102  Apple   HoneyCrisp  4.49
4   3/1/18  100201  Orange  Navel   2.49
12  3/29/18 100201  Orange  Navel   2.19

Thanks!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305577 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO