#22 Occupations (Using Pivot ) | HackerRank SQL Solutions
ฝัง
- เผยแพร่เมื่อ 18 ก.ย. 2022
- Check GroupBy Solution for same question here :
• #22 Occupations | Ha...
Copy code from here:
dev19community.blogspot.com/2...
Please follow us
/ dev.19.community
Thanks for watching us ...
Dev19🖤 - วิทยาศาสตร์และเทคโนโลยี
I think you can start ending each query with "';" because in oracle sql it is necessary as far as i remember.
Bhai ye query only oracle pe chalta hain MySQL pe nhi kyuki pivot function directly support nhi karta MySQL main!
how about this approch
SELECT
MAX(CASE WHEN Occupation = 'Doctor' THEN Name ELSE NULL END) AS Doctor,
MAX(CASE WHEN Occupation = 'Professor' THEN Name ELSE NULL END) AS Professor,
MAX(CASE WHEN Occupation = 'Singer' THEN Name ELSE NULL END) AS Singer,
MAX(CASE WHEN Occupation = 'Actor' THEN Name ELSE NULL END) AS Actor
FROM
OCCUPATIONS
GROUP BY
Name
ORDER BY
Name;
great
Your efforts are great! but unfortunately, the explanation of concepts is unorganized which I am sure you can explain way better once mapped. All the best :)
Can you explain what you mean by "You can explain way better once mapped"?
I watched his solution. It seems too hard for me.
Why max(name) is used here
to make it in an agregate clause format so that we dont have to use the column names in group by clause else it will deliver a undesired output
can we solve this in mysql....i can see that you are using oracle.
yes we can