I'm pretty new to SQL. I Have this table, how to write a code to filter the rows following these criteria. Each product filter by column item_revenue only shows the months with at least four positives or four negatives. So the result should show only product_A for February, product_B for January and February.
CodePudding user response:
Try this one:
select product_name, month
from mytable
group by product_name, month
having countif(item_revenue > 0) >= 4 OR countif(item_revenue < 0) >= 4