365 Days of Daily Coding Challenge: Day 105
I had a fantastic day today. I finished watching a Korean drama called “Hwarang”. Half of the time, I was pressing the right arrow key to finish the drama quickly lol. I also cooked momo which is one of the most popular fast food in Nepal. Every Nepalese love momo. It’s basically a dumpling with any stuffing of your choice. It could be vegetables like potatoes, spinach or cabbages or meat like pork or chicken. The highlight of the dish is the sauce which we call “achaar” made out of tomatoes and other ingredients like onions, corriander, chillis and so on.
I completed an advanced challenge today as well. I relied on the stack overflow for this one as I had no idea how it could be achieved. I learnt about a new function called LEVEL that is always accompanied by CONNECT BY. Level is a pseudocolumn used in hierarchical queries. You can learn more from here.
You could try out the below query in this site by Oracle here.
WITH temp AS (
Select 'Pencil' AS Product, 3 AS Quantity FROM Dual Union All
Select 'Eraser' AS Product, 4 AS Quantity FROM Dual Union All
Select 'Notebook' AS Product, 2 AS Quantity FROM Dual
)
SELECT t.Product, 1 AS Quantity
FROM temp t
JOIN (
SELECT level lvl FROM DUAL
CONNECT BY level <= (SELECT MAX(Quantity) FROM temp )
)rws
ON rws.lvl <= t.Quantity
ORDER BY 1, 2;

Leave a comment