朋友们,想转行数据吗?那我的第一个问题就会是,你会写SQL吗?
之前有推荐过几个SQL的课程,其实有了ChatGPT之后,连SQL课程都不需要了。甚至连在电脑上安装SQL,这件曾经让我很崩溃,几乎要放弃SQL的事情也不需要了。家庭教师ChatGPT都可以提供!
[ ⚠️ ]以下会有大量中英文夹杂,因为我不会翻译,介意的朋友可以优雅离场了。
今天来分享一下我测试ChatGPT来学习SQL的全过程,以及我用的prompt。有了ChatGPT,只要会打字就能学会SQL!
以下内容包括:
- 让ChatGPT给一个study plan;
- 让ChatGPT给题目,不要给答案,并且visualize 表格;
- 让ChatGPT分析解题思路;
- 让ChatGPT出面试题目;
- 让ChatGPT辅导写Leetcode
直接开始!
i don't have SQL on my computer, can you act as mysql
首先我问了ChatGPT它可不可以act as SQL server。它说不行。但是后面测试的时候,只要在对话框里打SQL syntax,它就可以理解啦。所以不用担心!
what are the most basic sql i should know about
接着我问它需要知道SQL最基础的内容。它给了回答。

can you come up with a study plan for SQL. i want to learn the basics one by one with practices.

can you give me a basic sql question practicing select statement only. please do not give me answer yet. please visualize the example tables with examples.
下一步的话,我们就可以开始练习啦!可以从最上面的一条SELECT
开始,让ChatGPT出题目。记得让它不要给答案先哦。并且可以让它数据的时候可以给一个例子。


how should i start thinking about this question.
但是我完全不会写SQL怎么办呢,那就问家庭教师呀。(不得不说,思路很清晰!)


到这里,我们就可以开始写写看。我故意写了错的答案,看一下它会怎么指导我。
select first name, last name, salary, from employees where salary >1000

这个题目比较简单。JOIN
是面试的时候经常会考到的题目,并且会考不同的JOIN之间的区别。所以我让ChatGPT给我一道JOIN的题目,但是不要告诉我是哪一种JOIN。
i want to practice join, including INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN. please give me a question to practice one of the joins. do not tell me which type of join i should use. visualize the example tables.

how the output should look like? can you visualize the output table
如果你觉得这个题目有一点点复杂,可以先让ChatGPT给一个output的样子,帮助理解。

how should i think about this question
还是觉得有一点不知道如何下手,那就让ChatGPT一步步拆解。

how to determine which type of join to use in this question?
在关于JOIN的题目里,决定哪一种JOIN是最重要的一步,我们也可以问ChatGPT。

select first_name, last_name, department_name, salary from employees join departments on department_id = department_id
这里我又故意给了错误的回答,在department_id前面没有加上table的名字。
ChatGPT就指出了这个错误,并且教我使用aliases。

在各种练习之后,我们可以开始准备面试了!
can you find a question used by facebook during data engineer interview

can you give me a more complex question that has been used in data engineer interviews
上面这个问题有一点点太简单啦,我就问有没有更难的问题。

最后的话来看一下ChatGPT如何辅导Leetcode SQL题目。 我随便找了一道Leetcode database的题目,https://leetcode.cn/problems/second-highest-salary/,复制粘贴给ChatGPT。

can you explain?

what if we want to get the Nth highest salary?

what does 'LIMIT n-1, 1 ' mean?
这里出现了一个新的概念Offset,于是就追问一下。

总结一下:
上面是我测试如果用ChatGPT来自学SQL的实录。总结一下:
- ChatGPT教得很好;
- SQL最主要的学习方式就是练习以及解题思路,可以让ChatGPT给很多练习题,并且让它给出如何一步步思考的过程;
- 遇到不会写的题目,就拿给ChatGPT吧!
About Me:
很开心遇见你!我是穿堂风,也是Simona。曾经的资深互联网数据打工人(Data Engineer),2022年11月被Facebook裁员后,开启数字游民生活。
我正在做的项目和提供的服务在我的个人主页。https://simona.life/