If you already have a table, view or subquery that contains these three columns, then try something like this:
select *, case when [Month 1] = 'NEET' or [Month 2] = 'NEET' or [Month 3] = 'NEET' then 'NO' else 'YES' end as Target
from MyTable
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Good Afternoon,
I am relatively new to SQL and have come across something I can easily do in Excel but I need to replicate in SQL. I am looking back at the last 3 months of data for each individual and making an overall decision. So if any of the last 3 months contain "NEET" then it needs to return "NO". If the last 3 months contain all or a combination of "NOT NEET" or BLANK then "YES" . You can see the simple formula being used below:
I have been able to group my data in SQL by month, but it is the next stage, the overall category that I am unable how to create:
Any advice or guidance, would be much appreciated. Many Thanks
If you already have a table, view or subquery that contains these three columns, then try something like this:
select *, case when [Month 1] = 'NEET' or [Month 2] = 'NEET' or [Month 3] = 'NEET' then 'NO' else 'YES' end as Target
from MyTable
Hi @Lee_Walmsley
If you have written the SQL to group data by month ,please refer to this :
;WITH CTE as
(
--Put the Sql statement that you group your data by month here
)
SELECT individual_name,[Month 1],[Month 2],[Month 3],
CASE WHEN [Month 1] IS NULL AND [Month 2] IS NULL AND [Month 3] IS NULL THEN 'NONE RECORDED'
WHEN [Month 1] = 'NEET' OR [Month 2] = 'NEET' OR [Month 3] = 'NEET' THEN 'NO' ELSE 'YES' END AS TARGET
FROM CTE
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.