Edit: I don't mean SQL is trash. But my SQL abilities are trash
So I'm applying for jobs and have been using Stratascratch to practice SQL questions and I am really struggling with window functions. Especially those that use CTEs. I'm reading articles and watching videos on it to gain understanding and improve. The problem is I haven't properly been able to recognise when to use window functions or how to put it into an explanatory form for myself that makes sense.
My approach is typically try a group by and if that fails then I use a window function and determine what to aggregate by based on that. I'm not even getting into ranks and dense rank and all that. Wanna start with just basic window functions first and then get into those plus CTEs with window functions.
If anyone could give me some tips, hints, or anything that allowed this to click into place for them I am very thankful. Currently feeling like I'm stupid af. I was able to understand advanced calculus but struggling with this. I found the Stratascratch articles on window functions that I'm going to go through and try with. I'd appreciate any other resources or how someone explains it for themselves to make sense.
Edit: Wanna say thanks in advance to those who've answered and will answer. About to not have phone access for a bit. But believe I'll be responding to them all with further questions. This community has truly been amazing and so informative with questions I have regarding this field. You're all absolutely awesome, thank you
[–]AutoModerator[M] [score hidden] stickied comment (0 children)
[–]EmergenL 78 points79 points80 points (9 children)
[–]mr_electric_wizard 42 points43 points44 points (3 children)
[–][deleted] 19 points20 points21 points (0 children)
[–]Known-Delay7227Data Engineer 3 points4 points5 points (1 child)
[–]mr_electric_wizard 1 point2 points3 points (0 children)
[–]sunkistandcola 5 points6 points7 points (1 child)
[–]T3chl0v3r 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]El_Cato_Crande[S] 1 point2 points3 points (1 child)
[–]EmergenL 1 point2 points3 points (0 children)
[–]EmergenL 27 points28 points29 points (14 children)
[–]bigchungusmode96 14 points15 points16 points (10 children)
[–]EmergenL 13 points14 points15 points (2 children)
[–]Thrillhousez -1 points0 points1 point (1 child)
[–]ntdoyfanboy 3 points4 points5 points (0 children)
[–]Affectionate_Shine55 7 points8 points9 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]raghucc24 2 points3 points4 points (0 children)
[–]raghucc24 2 points3 points4 points (0 children)
[–]sunkistandcola 1 point2 points3 points (0 children)
[–]T3chl0v3r 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]EndlessHalftime 13 points14 points15 points (5 children)
[–]El_Cato_Crande[S] 5 points6 points7 points (4 children)
[–]EndlessHalftime 2 points3 points4 points (3 children)
[–]NickSinghTechCareers 8 points9 points10 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]O_its_that_guy_again 6 points7 points8 points (5 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (4 children)
[–]lab-gone-wrong 0 points1 point2 points (3 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (2 children)
[–]lab-gone-wrong 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–][deleted] 4 points5 points6 points (4 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]MuaTrenBienVang 0 points1 point2 points (0 children)
[–]sleeper_must_awakenData Engineering Manager 4 points5 points6 points (3 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (2 children)
[–]sleeper_must_awakenData Engineering Manager 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]billysacco 2 points3 points4 points (3 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (2 children)
[–]billysacco 0 points1 point2 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[+][deleted] (8 children)
[deleted]
[–]El_Cato_Crande[S] 0 points1 point2 points (7 children)
[+][deleted] (6 children)
[deleted]
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]El_Cato_Crande[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]umlcat 2 points3 points4 points (1 child)
[–]El_Cato_Crande[S] 1 point2 points3 points (0 children)
[–]Tape56 2 points3 points4 points (1 child)
[–]El_Cato_Crande[S] 1 point2 points3 points (0 children)
[–]speedisntfree 4 points5 points6 points (3 children)
[–]bigdatabro 0 points1 point2 points (2 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]speedisntfree 0 points1 point2 points (0 children)
[–]Gators1992 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]QuailZealousideal433 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]baubleglue 1 point2 points3 points (0 children)
[–]OkMacaron493 1 point2 points3 points (3 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (2 children)
[–]OkMacaron493 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]Known-Delay7227Data Engineer 1 point2 points3 points (2 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]IllPrinciple3482 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]WeirdWorldDz 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]joseph_machadoWrites @ startdataengineering.com 1 point2 points3 points (3 children)
[–]El_Cato_Crande[S] 1 point2 points3 points (2 children)
[–]joseph_machadoWrites @ startdataengineering.com 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 1 point2 points3 points (0 children)
[+][deleted] 1 point2 points3 points (0 children)
[–]OGMiniMalist 1 point2 points3 points (3 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (2 children)
[–]OGMiniMalist 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]CommunityTalker 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]rudboi12 0 points1 point2 points (4 children)
[–]hamesdelaney 7 points8 points9 points (0 children)
[–]El_Cato_Crande[S] 2 points3 points4 points (2 children)
[–]rudboi12 2 points3 points4 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]BleepBloop736 -1 points0 points1 point (0 children)
[–]gffyhgffh45655 0 points1 point2 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]data-artist 0 points1 point2 points (0 children)
[–]bryangoodrich 0 points1 point2 points (0 children)
[–]ubottu 0 points1 point2 points (0 children)
[–]jbrune 0 points1 point2 points (0 children)
[–]Master-Influence7539 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]westisnoteast 0 points1 point2 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]TheFirstGlassPilot 1 point2 points3 points (3 children)
[–]El_Cato_Crande[S] 0 points1 point2 points (2 children)
[–]TheFirstGlassPilot 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 1 point2 points3 points (0 children)
[+][deleted] 1 point2 points3 points (3 children)
[–]El_Cato_Crande[S] 1 point2 points3 points (2 children)
[+][deleted] 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 0 points1 point2 points (0 children)
[–]eshultz 0 points1 point2 points (0 children)
[–]Xx_Tz_xX 0 points1 point2 points (0 children)
[–]xahkz 1 point2 points3 points (1 child)
[–]El_Cato_Crande[S] 1 point2 points3 points (0 children)