I don't have much experience in SQL and I am finding difficult to construct the query for the following problem.
Let's say I have sales per month data as follows and is saved in Redshift
ProductId Year Month Sales
A 2018 1 345
A 2018 2 3425
A 2018 3 56545
A 2018 4 234
A 2018 5 23
B 2018 1 645
B 2018 2 2324
B 2018 3 123
B 2018 4 700
B 2018 5 1410
....
....
....
I want to extract the following information from the above table. The query in plain English looks as follows.
Select the product (group by) where sales are greater than 800 for the month 2018/3. For this query, product "A" data should be returned with the sales value for month 2018/3
Select the product (group by) where the sale of month 2018/5 is 100% greater than 2018/4. Here only product "B" is matched and sales data of both months should be included in the result.
Edit: Expected result added.
For query 1
ProductId Year Month Sales
A 2018 3 56545
For query 2 (Grouped)
ProductId Increase Year Month Sales
B 101.42 % 2018 5 1410
2018 4 700