Can you please help me on how to achieve the below-expected result from the dataset given.
|SKU||Available date||Used Date||Availble Count||Used Count|
Is available & used date always the same day?
Then it's a simple conditional aggregation:
SELECT SKU, Max(CASE WHEN Status = 'Available' THEN date END), Max(CASE WHEN Status = 'Used' THEN date end), Count(CASE WHEN Status = 'Available' THEN date END), Count(CASE WHEN Status = 'Used' THEN date END) FROM tab GROUP BY SKU, DATE
Otherwise which rules exits to assigned those dates to a row?