Nick Holt
Transform Your SQL Skills with Unique Video Training & Mentorship Program | Online Tuition + Weekly Q&A Support
- Report this post
I think CTEs are the most misunderstood element of SQL.Recent posts I've seen here on this platform demonstrate a frightening lack of awareness about their function, affect on performance and overall usefulness.Thereโs an awful lot of rubbish spoken about CTEs both in LinkedIn and in articles.Some key headlines about CTEs:๐They exist to aid readability๐You can split up a long and complex query into small bitesize chunks๐Thereโs no practical limit to the number of CTEs you can have in a query๐CTEs enable easier troubleshooting of a query.๐They CAN help improve performance (as advised by Brent Ozar), but in most cases thereโs little or no performance benefit.๐CTEs last only as long as the current query execution. ๐You can nest CTEs using a technique called โdaisy-chainingโ where you refer to one CTE inside another. I wouldnโt recommend this personally.--------------------------------------------------------------------About me:I help individuals learn SQL to advance their own careersI help businesses get their data/BI teams skilled up in SQLBook an appointment to speak to me about how I can help you--------------------------------------------------------------------#sql#thebischool#learnsql#sqluk#CTEs
43
6 Comments
Richard Bennett
Data Leader
9mo
- Report this comment
And most excitingly they can use recursion to solve some interesting challenges.
1Reaction 2Reactions
To view or add a comment, sign in
More Relevant Posts
-
Nick Holt
Transform Your SQL Skills with Unique Video Training & Mentorship Program | Online Tuition + Weekly Q&A Support
- Report this post
I think CTEs are the most misunderstood element of SQL.Recent posts I've seen here on this platform demonstrate a frightening lack of awareness about their function, affect on performance and overall usefulness.Thereโs an awful lot of rubbish spoken about CTEs both in LinkedIn and in articles.Some key headlines about CTEs:๐They exist to aid readability๐You can split up a long and complex query into small bitesize chunks๐Thereโs no practical limit to the number of CTEs you can have in a query๐CTEs enable easier troubleshooting of a query.๐They CAN help improve performance (as advised by Brent Ozar), but in most cases thereโs little or no performance benefit.๐CTEs last only as long as the current query execution. ๐You can nest CTEs using a technique called โdaisy-chainingโ where you refer to one CTE inside another. I wouldnโt recommend this personally.---------------------------------------------------------------------------About me:I help individuals learn SQL to advance their own careersI help businesses get their data/BI teams skilled up in SQLVisit my website and there you can book an appointment to speak to me about how I can help you---------------------------------------------------------------------------#sql#thebischool#learnsql#sqluk#CTEs
34
4 Comments
Like CommentTo view or add a comment, sign in
-
Sachin S.
Data Analyst
- Report this post
๐ Unlocking the Power of SQL with CTEs! ๐I recently used a Common Table Expression (CTE) to solve a tricky data analysis problem and wanted to share how helpful they can be. Here's a snippet of the query:-----------------------------------------------------------------------------------with cte as (select user_id,sum(case when activity_type = 'open' then time_spent else 0 end) as ot,sum(case when activity_type = 'send' then time_spent else 0 end) as stfrom activitiesgroup by user_id)select a.age_bucket , (c.st/(c.st+c.ot))*100.0 as send_perc, (c.ot/(c.st+c.ot))*100.0as open_percfrom cte cRight join age_breakdown aon c.user_id = a.user_id-------------------------------------------------------------------------------------๐ Why CTEs Rock:- Clarity: Breaks complex queries into manageable chunks.- Reusability: Reference CTEs multiple times in your query.- Organization: Keeps your main query clean and focused.CTEs have made my SQL queries so much cleaner and easier to understand. If you haven't used them yet, give them a try!How have you used CTEs in your work? Share your experiences below!#DataScience #SQL #CTE #DataAnalytics #TechTips
4
1 Comment
Like CommentTo view or add a comment, sign in
-
Gayatri Gattani
MSDS student | Python | SQL | Machine Learning | Data Science
- Report this post
๐ ๐๐ป๐ต๐ฎ๐ป๐ฐ๐ฒ ๐ฌ๐ผ๐๐ฟ ๐ฆ๐ค๐ ๐ฆ๐ธ๐ถ๐น๐น๐ ๐๐ถ๐๐ต ๐ฎ ๐๐๐ง๐-๐ณ๐ผ๐ฐ๐๐๐ฒ๐ฑ ๐๐ต๐ฎ๐น๐น๐ฒ๐ป๐ด๐ฒ! ๐In the world of data, SQL stands as a cornerstone, enabling us to navigate through complex databases with ease. Today, I want to spotlight a unique aspect of SQL that often presents intriguing challenges: the ๐๐๐ง๐ ๐ฑ๐ฎ๐๐ฎ๐๐๐ฝ๐ฒ.Handling dates in SQL can be tricky, yet it's crucial for generating insightful analyses and reports. To help you sharpen your skills in this area, I'm sharing ๐๐ต๐ฟ๐ฒ๐ฒ ๐๐ฒ๐ฒ๐๐๐ผ๐ฑ๐ฒ ๐ฐ๐ต๐ฎ๐น๐น๐ฒ๐ป๐ด๐ฒ๐ that are perfect for anyone looking to delve deeper into SQL's capabilities with dates:๐ ๐ผ๐ป๐๐ต๐น๐ ๐ง๐ฟ๐ฎ๐ป๐๐ฎ๐ฐ๐๐ถ๐ผ๐ป๐ ๐ - A fantastic starting point to practice aggregating data over time. Check it out here : https://lnkd.in/gXhfZUEd๐๐บ๐บ๐ฒ๐ฑ๐ถ๐ฎ๐๐ฒ ๐๐ผ๐ผ๐ฑ ๐๐ฒ๐น๐ถ๐๐ฒ๐ฟ๐ ๐๐ - This challenge takes you a step further, asking you to calculate rates and percentages over specific time periods. Dive in here: https://lnkd.in/gtd9K2Ug๐๐ฎ๐บ๐ฒ ๐ฃ๐น๐ฎ๐ ๐๐ป๐ฎ๐น๐๐๐ถ๐ ๐๐ฉ - A more advanced challenge that tests your ability to perform complex analyses over different time frames. Give it a go here: https://lnkd.in/gdGWUE_pWhy not take this opportunity to challenge yourself and perhaps even a colleague? Let's share our solutions and learning experiences. Drop your thoughts, tips, or any questions you might have in the comments below. Let's grow together in our SQL journey!๐๐ฎ๐ฝ๐ฝ๐ ๐ค๐๐ฒ๐ฟ๐๐ถ๐ป๐ด! ๐#SQL #DataAnalysis #CodingChallenge #LeetCode #ProfessionalDevelopment #ContinuousLearning
42
3 Comments
Like CommentTo view or add a comment, sign in
-
Venkata Naga Sai Kumar Bysani
Data Scientist | 70K LinkedIn | BCBS Of South Carolina | SQL | Python | AWS | ML | Featured on Times Square, Favikon, Fox, NBC | MS in Data Science at UConn | Proven record in driving insights and predictive analytics |
- Report this post
Once you've learned/mastered the fundamentals of SQL, try learning these:- ๐๐๐๐๐ฌ: LEFT, RIGHT, INNER, OUTER joins.- ๐๐ ๐ ๐ซ๐๐ ๐๐ญ๐ ๐ ๐ฎ๐ง๐๐ญ๐ข๐จ๐ง๐ฌ: Utilize SUM, COUNT, AVG, and others for efficient data summarization.- ๐๐๐๐ ๐๐๐๐ ๐๐ญ๐๐ญ๐๐ฆ๐๐ง๐ญ๐ฌ: Use conditional logic to tailor query results.- ๐๐๐ญ๐ ๐๐ข๐ฆ๐ ๐ ๐ฎ๐ง๐๐ญ๐ข๐จ๐ง๐ฌ: Master manipulating dates and times for precise analysis.Next, explore advanced methods to structure and reuse SQL code effectively:- ๐๐จ๐ฆ๐ฆ๐จ๐ง ๐๐๐๐ฅ๐ ๐๐ฑ๐ฉ๐ซ๐๐ฌ๐ฌ๐ข๐จ๐ง๐ฌ (๐๐๐๐ฌ): Simplify complex queries into manageable parts to increase the readability.- ๐๐ฎ๐๐ช๐ฎ๐๐ซ๐ข๐๐ฌ: Nest queries for more granular data retrieval.- ๐๐๐ฆ๐ฉ๐จ๐ซ๐๐ซ๐ฒ ๐๐๐๐ฅ๐๐ฌ: Create and manipulate temporary data sets for specific tasks.Then, move on to advanced ones:- ๐๐ข๐ง๐๐จ๐ฐ ๐ ๐ฎ๐ง๐๐ญ๐ข๐จ๐ง๐ฌ: Perform advanced calculations over sets of rows with ease.- ๐๐ญ๐จ๐ซ๐๐ ๐๐ซ๐จ๐๐๐๐ฎ๐ซ๐๐ฌ: Create reusable SQL routines for streamlined operations.- ๐๐ซ๐ข๐ ๐ ๐๐ซ๐ฌ: Automate database actions based on specific events.- ๐๐๐๐ฎ๐ซ๐ฌ๐ข๐ฏ๐ ๐๐๐๐ฌ: Solve complex problems using recursive queries.- ๐๐ฉ๐ญ๐ข๐ฆ๐ข๐ณ๐๐ญ๐ข๐จ๐ง ๐จ๐ ๐๐ฎ๐๐ซ๐ข๐๐ฌ: Techniques to enhance performance and efficiency.What other essential SQL skills would you add to this learning journey? ๐๐ง๐๐ ๐ฒ๐จ๐ฎ ๐ฅ๐๐๐ซ๐ง ๐จ๐ซ ๐๐ฌ ๐ฒ๐จ๐ฎ ๐ฅ๐๐๐ซ๐ง, ๐ฉ๐ซ๐๐๐ญ๐ข๐๐ ๐๐๐ ๐ก๐๐ซ๐:1. Dataford - https://lnkd.in/dau5UwmN2. InterviewQuery - https://lnkd.in/dzJET9aC3. LeetCode - https://lnkd.in/gkCpv7NA4. HackerRank - https://lnkd.in/exe3kXzD#sql #dataanalytics #interviewprep
325
54 Comments
Like CommentTo view or add a comment, sign in
-
Md Ashraf
MIS Executive @Sita Fashions Pvt. Ltd. |||| Advanced Excel || SQL || Power BI || Python || VBA || Alike Mentor||Curious to learn||
- Report this post
Hey everyone! After a break from SQL, I've recently jumped back into the world of data, and itโs like coming home!But, as with any return, Iโve stumbled upon a few bumps along the way.Here are some common mistakes Iโve caught myself making: โ Syntax Errors: Missing semicolons or using wrong keywords.โ JOIN Mistakes: Mixing up INNER JOIN and OUTER JOIN or joining on incorrect columns.โ GROUP BY Problems: Not using aggregate functions properly. โ NULL Handling: Forgetting to use IS NULL or IS NOT NULL. โ SELECT * Overuse: Slowing down queries by selecting unnecessary data.โ Ignoring Indexes: Not adding indexes for faster querying.Itโs been a learning curve, but every mistake is a chance to improve.When I first returned to SQL, I found that while I remembered the core concepts, some syntax and details had slipped my mind.I also had to readdress my tendency to overuse SELECT *, which was impacting query performance.To get back on track, hereโs what helped me:Revisit the Basics: Refreshing my memory with tutorials and documentation.Practice Regularly: Working on small exercises and sample databases.Use a Cheat Sheet: Keeping a reference guide handy for quick reminders.Write and Review Code: Practicing queries and reviewing them to spot mistakes.Itโs all about patience and persistence. Each mistake is a stepping stone towards mastery.How do you handle jumping back into skills after a break? Letโs share tips and support each other!#SQL #SQLMistakes #Linkedin
26
2 Comments
Like CommentTo view or add a comment, sign in
-
John Pauler
John Pauler is an Influencer
Learn data skills @ Maven Analytics
- Report this post
Here's how you can create dynamic projections in your reporting. We'll use SQL for the example, but the same logic can be applied to whatever tool your using.Here's the code from the video so you can copy it down and follow along on your own: -- number of days in current monthSELECT DAY(LAST_DAY(NOW()))-- ,NOW()-- ,LAST_DAY(NOW());-- first day of current month SELECT DATE_FORMAT(NOW(),'%Y-%m-01') AS first_day;-- seconds into this month so farSELECT TIMESTAMPDIFF(SECOND, DATE_FORMAT(NOW(),'%Y-%m-01'), NOW()) AS secs;-- total seconds in this month SELECT DAY(LAST_DAY(NOW())) * 86400; SELECT DAY(LAST_DAY(NOW())) * 86400 / TIMESTAMPDIFF(SECOND, DATE_FORMAT(NOW(),'%Y-%m-01'), NOW())AS total_to_current_ratio , TIMESTAMPDIFF(SECOND, DATE_FORMAT(NOW(),'%Y-%m-01'), NOW()) / (DAY(LAST_DAY(NOW())) * 86400)AS pct_through_monthFor folks who are interesting in improving their SQL skills, check out our MySQL Specialist Path or our individual courses. MYSQL SPECIALIST LEARNING PATH: https://lnkd.in/eTpUrqwZ#learning #sql #data #analysis #datascience #businessintelligence #careers
44
2 Comments
Like CommentTo view or add a comment, sign in
-
John Pauler
John Pauler is an Influencer
Learn data skills @ Maven Analytics
- Report this post
Here's how you can create dynamic projections in your reporting. We'll use SQL for the example, but the same logic can be applied to whatever tool your using.Here's the code from the video so you can copy it down and follow along on your own: -- number of days in current monthSELECT DAY(LAST_DAY(NOW()))-- ,NOW()-- ,LAST_DAY(NOW());-- first day of current month SELECT DATE_FORMAT(NOW(),'%Y-%m-01') AS first_day;-- seconds into this month so farSELECT TIMESTAMPDIFF(SECOND, DATE_FORMAT(NOW(),'%Y-%m-01'), NOW()) AS secs;-- total seconds in this month SELECT DAY(LAST_DAY(NOW())) * 86400; SELECT DAY(LAST_DAY(NOW())) * 86400 / TIMESTAMPDIFF(SECOND, DATE_FORMAT(NOW(),'%Y-%m-01'), NOW())AS total_to_current_ratio , TIMESTAMPDIFF(SECOND, DATE_FORMAT(NOW(),'%Y-%m-01'), NOW()) / (DAY(LAST_DAY(NOW())) * 86400)AS pct_through_monthFor folks who are interesting in improving their SQL skills, check out our MySQL Specialist Path or our individual courses. MYSQL SPECIALIST LEARNING PATH: https://lnkd.in/eTpUrqwZ#learning #sql #data #analysis #datascience #businessintelligence #careers
79
4 Comments
Like CommentTo view or add a comment, sign in
-
Anjusha Rajan, M.Eng
Google Certified Business Intelligence and Data Analyst | Strategizing Scalable AI Solutions for Tomorrow's Challenges | AI/ML | SQL |Azure |Data Visualization
- Report this post
๐ก Heres a tip by John Pauler if you would love to learn 'how to add dynamic projections to your reporting ' . โก Dynamic reporting dynamically updates reports in response to changes in underlying data sources. โก We can discover how to calculate an estimated projection for the end of the month, like May, dynamically for any Key Performance Indicator (KPI).#dataanalyst #reporting #sqlqueries
12
2 Comments
Like CommentTo view or add a comment, sign in
-
Kirolos Daniel
Data Engineer | Data Analyst | Azure Certified | Freelancer | Financial Analyst @EvaPharma
- Report this post
While working on a SQL problem this morning, I reflected on how my problem-solving approach has significantly evolved over time. Itโs fascinating to observe how practice has refined my thinking process compared to when I first began.Now, when faced with a SQL challenge, Iโve discovered that taking a thoughtful and deliberate approach yields far better results than rushing to a solution. I start by thoroughly analyzing the dataโreviewing its attributes and key information to gain a comprehensive understanding of its structure.Once I have a clear grasp of the data, I carefully read the problem statement to ensure I fully comprehend what is being asked. Before diving into writing queries, I take a moment to draft a step-by-step plan. This strategy is particularly useful for tackling complex problems that involve subqueries, joins, or regular expressions.By investing time in planning my solution, I find that I can approach problems more efficiently and accurately.How do you approach SQL challenges? comment below ๐
1
Like CommentTo view or add a comment, sign in
-
Prerna S.
Campus Ambassador @ InternsElite | Empowering Students with Career Opportunities | Leadership & Networking Advocate
- Report this post
๐ Day 7 of My SQL Learning Journey: Unlocking the Power of LIKE Queries! ๐Today, I explored the versatility of LIKE queries in SQL, which are essential for pattern matching and flexible data retrieval. ๐๐Hereโs what I accomplished on Day 7:- ๐ Learned how to use the LIKE keyword to search for patterns within text data.- ๐งฉ Practiced using wildcards (%) and (_) to create flexible search conditions.- ๐ ๏ธ Combined LIKE with SELECT, WHERE, and other SQL clauses for dynamic queries.- ๐ Explored practical examples, such as finding all records with a certain prefix, suffix, or substring.LIKE queries are incredibly powerful for filtering and extracting data based on specific patterns, making them indispensable for data analysis and reporting.Iโm excited to continue my SQL journey and apply these techniques to real-world scenarios. Your support and insights have been invaluable!If you have any tips or interesting use cases for LIKE queries, Iโd love to hear them. Letโs keep pushing the boundaries of what we can do with SQL! ๐#SQL #DataManagement #LearningJourney #ProfessionalDevelopment #Day7 #DataAnalytics #LikeQueries
16
Like CommentTo view or add a comment, sign in
18,526 followers
- 736 Posts
View Profile
FollowExplore topics
- Sales
- Marketing
- IT Services
- Business Administration
- HR Management
- Engineering
- Soft Skills
- See All