💪Beats 82.35% | 💯Detailed Solution Breakdown | 👀Must See
# \uD83D\uDD38 Note :\n- `Solution-1` : is more of a generalised solution which is better for real world scenario\n- `Solution-2` : is just as per the problem statement i.e. specifically for feb-2020\n---\n# \uD83D\uDD39 Code :\n```mssql []\n/* ********* SOLUTION-1 ********* */\n-- this is a generalised solution for data of any year\nSELECT product_name,SUM(unit) AS unit\nFROM Products AS P JOIN Orders AS O\nON P.product_id = O.product_id \n-- group according to year then month wise then product id\n-- since we need product_name in the SELECT clause we have used that here in GROUP_BY clause \nGROUP BY YEAR(order_date),MONTH(order_date), P.product_id,P.product_name\n-- in each group, we need data or below two conditions\nHAVING MONTH(order_date) = 2 AND SUM(unit) >= 100\n\n/* ********* SOLUTION-2 ********* */\nSELECT product_name,SUM(unit) AS unit\nFROM Products AS P JOIN Orders AS O\nON P.product_id = O.product_id  \nGROUP BY YEAR(order_date),MONTH(order_date), P.product_id,P.product_name\nHAVING MONTH(order_date) = 2 AND SUM(unit) >= 100\n\nSELECT P.product_name,SUM(unit) as unit \nFROM Products AS P JOIN Orders AS O \nON P.product_id = O.product_id \nWHERE order_date >= \'2020-02-01\' AND order_date <=\'2020-02-29\'\nGROUP BY P.product_id, P.product_name\nHAVING SUM(unit) >= 100\n```\n---\n#### \uD83D\uDC4D <span style="background-image: linear-gradient(to right, #fa709a 0%, #fee140 100%);-webkit-background-clip: text;-webkit-text-fill-color: transparent;"/> Please UPVOTE so that i can revise this question each time someone UPVOTES IT.</span>\n\n<img src="https://assets.leetcode.com/users/images/87393e0b-4ccf-478a-83ee-d17fff4e8f87_1727076778.2163403.jpeg" alt="upvote_cat" width="200"/>\n\nTags: `SQL`, `tips`, `beginner`, `optimization`\n\nFeel free to share your tips or ask any questions below! Let\u2019s help each other level up \uD83D\uDE80!\n\uD83D\uDCAA Keep Grinding \n\uD83D\uDE0A Happy Coding! \n
['MS SQL Server']