Multiple ways of solving in MySQL
Approach 1(With CTE)\n\n\nWITH sell_history AS (\n    SELECT\n        s.product_id,\n        SUM(CASE WHEN sale_date NOT BETWEEN \'2019-01-01\' AND \'2019-03-31
**Approach 1(With CTE)**\n\n```\nWITH sell_history AS (\n    SELECT\n        s.product_id,\n        SUM(CASE WHEN sale_date NOT BETWEEN \'2019-01-01\' AND \'2019-03-31\' THEN 1 ELSE 0 END) sold_outside,\n        SUM(CASE WHEN sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\' THEN 1 ELSE 0 END) sold_inside\n    FROM sales s \n    GROUP BY s.product_id\n)\n\nSELECT\n    s.product_id,\n    p.product_name\nFROM sell_history s \nLEFT JOIN product p ON p.product_id = s.product_id\nWHERE s.sold_outside = 0 \nAND s.sold_inside > 0;\n```\n\n**Approach 2(Using subquery with JOIN & GROUP BY)**\n\n```\nSELECT\n    s.product_id,\n    p.product_name\nFROM sales s \nLEFT JOIN product p ON p.product_id = s.product_id\nGROUP BY s.product_id\nHAVING s.product_id NOT IN (\n    SELECT product_id FROM sales WHERE sale_date NOT BETWEEN \'2019-01-01\' AND \'2019-03-31\'\n);\n```\n\n**Approach 3(Using subquery with no JOIN)**\n\n```\nSELECT\n    product_id,\n    product_name\nFROM product\nWHERE product_id NOT IN (\n    SELECT product_id FROM sales WHERE sale_date NOT BETWEEN \'2019-01-01\' AND \'2019-03-31\'\n)\n```
['MySQL']