Comments on: SQL for Data Analysis – Tutorial – ep6 (advanced stuff) https://data36.com/sql-data-analysis-advanced-tutorial-ep6/ Learn Data Science the Hard Way! Fri, 16 Feb 2024 11:06:12 +0000 hourly 1 https://wordpress.org/?v=6.7.4 By: Tomi Mester https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-191236 Tue, 08 Dec 2020 15:09:08 +0000 https://data36.com/?p=1287#comment-191236 In reply to Nisha.

hey Nisha — I updated the article after all.
Thanks for the note! 😉

]]>
By: Tomi Mester https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-64602 Wed, 06 Mar 2019 11:16:27 +0000 https://data36.com/?p=1287#comment-64602 In reply to Samuel Wulf.

Yeah, spot-on – and indeed, Nisha has already found this one.

Regardless: Great catch and thanks for the comment!

PS. And keep going with the Python and bash articles. : )

]]>
By: Samuel Wulf https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-62371 Sat, 23 Feb 2019 19:12:38 +0000 https://data36.com/?p=1287#comment-62371 Ooops, I see somebody already posted the code I just wrote here…

]]>
By: Samuel Wulf https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-62370 Sat, 23 Feb 2019 19:11:25 +0000 https://data36.com/?p=1287#comment-62370 Dear Tomi!

Thank you for the awesome tutorial. I enjoyed working my through it. I will also continue with the bash and the Python tutorials soon 🙂

I just have one question to SQL now:
For the first example you have here in this last article (where we should only print the tailnumber of the plane) i found a solution which seems to be working, without using any subqueries:

SELECT
tailnum
FROM flight_delays
GROUP BY tailnum
ORDER BY AVG(depdelay) DESC
LIMIT 10;

I just added the avg when I was about to order the list. The results turned out to be the same as your results. It looks correct to me. Is this something which one could do, or is it maybe less ‘proper’ to use it this way?

]]>
By: Tomi Mester https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-22580 Tue, 19 Jun 2018 23:57:09 +0000 https://data36.com/?p=1287#comment-22580 In reply to William.

hi William! Glad to hear! 😉 And thanks for the feedback! Tomi

]]>
By: William https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-21428 Sun, 03 Jun 2018 17:02:50 +0000 https://data36.com/?p=1287#comment-21428 Thank you Tomi for this awesome tutorial. I learned SQL from scratch and this tutorial is super helpful. Thank you very much!!!

]]>
By: Tomi Mester https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-14633 Wed, 11 Apr 2018 16:55:54 +0000 https://data36.com/?p=1287#comment-14633 In reply to Xiao.

hi Xiao,
hmm. tricky – TBH, I’m not really familiar with MS SQL, sorry… but it’s like 99.9% sure that issue comes from the difference between MS SQL and PostgreSQL.
Tomi

]]>
By: Xiao https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-13473 Wed, 21 Mar 2018 16:49:35 +0000 https://data36.com/?p=1287#comment-13473 In reply to Tomi Mester.

Hi Tomi,

thanks for your reply.

I just tested case statement + Group by , seems the combination does not work, getting error of “Invalid column name”. I am just curious about when you run your query, did you meet any error or simply got the output?
PS. I used MS SQL.

Thanks,
Xiao

]]>
By: Tomi Mester https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-13254 Fri, 16 Mar 2018 13:30:17 +0000 https://data36.com/?p=1287#comment-13254 In reply to Xiao.

hi Xiao,

thanks for the question! To be honest, I don’t know the exact answer and I couldn’t find anything online that provides a definite answer for your question… Although, my best guess is that “CASE” executed – independently from the SELECT statement – before the GROUP BY statement.
But if anyone finds a better answer, don’t hesitate to comment!

Tomi

]]>
By: Xiao https://data36.com/sql-data-analysis-advanced-tutorial-ep6/#comment-13189 Tue, 13 Mar 2018 16:26:10 +0000 https://data36.com/?p=1287#comment-13189 Hi Tomi,

Very good posts and website that I have learned lots of knowledge of Data Analytics, thanks.

Just wonder how this following code “Group by segment” works

SELECT COUNT(*),
CASE WHEN depdelay 0 THEN ‘late’
ELSE ‘ontime’
END as segment
FROM flight_delays
GROUP BY segment
LIMIT 10;

because Group by comes before Select, when SQL executes group by segment, SQL did not recognize “segment” which comes from Select clause.

I don’t know if my understanding is correct, but you still got results.

]]>