朋友们,想转行数据吗?那我的第一个问题就会是,你会写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最基础的内容。它给了回答。
![ChatGPT-SQL篇(会打字就能学会SQL)插图 Screenshot 2023-03-20 at 2.24.18 PM.png](https://i.typlog.com/simona/8320706521_507283.png)
can you come up with a study plan for SQL. i want to learn the basics one by one with practices.
![ChatGPT-SQL篇(会打字就能学会SQL)插图1 Screenshot 2023-03-20 at 3.01.19 PM.png](https://i.typlog.com/simona/8320704308_946776.png)
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出题目。记得让它不要给答案先哦。并且可以让它数据的时候可以给一个例子。
![ChatGPT-SQL篇(会打字就能学会SQL)插图2 Screenshot 2023-03-20 at 2.29.07 PM.png](https://i.typlog.com/simona/8320706230_761635.png)
![ChatGPT-SQL篇(会打字就能学会SQL)插图3 Screenshot 2023-03-20 at 2.29.15 PM.png](https://i.typlog.com/simona/8320706224_805501.png)
how should i start thinking about this question.
但是我完全不会写SQL怎么办呢,那就问家庭教师呀。(不得不说,思路很清晰!)
![ChatGPT-SQL篇(会打字就能学会SQL)插图4 Screenshot 2023-03-20 at 2.31.08 PM.png](https://i.typlog.com/simona/8320706112_474162.png)
![ChatGPT-SQL篇(会打字就能学会SQL)插图5 Screenshot 2023-03-20 at 2.31.14 PM.png](https://i.typlog.com/simona/8320706104_640097.png)
到这里,我们就可以开始写写看。我故意写了错的答案,看一下它会怎么指导我。
select first name, last name, salary, from employees where salary >1000
![ChatGPT-SQL篇(会打字就能学会SQL)插图6 Screenshot 2023-03-20 at 2.34.55 PM.png](https://i.typlog.com/simona/8320705891_812887.png)
这个题目比较简单。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.
![ChatGPT-SQL篇(会打字就能学会SQL)插图7 Screenshot 2023-03-20 at 2.38.01 PM.png](https://i.typlog.com/simona/8320705707_534856.png)
how the output should look like? can you visualize the output table
如果你觉得这个题目有一点点复杂,可以先让ChatGPT给一个output的样子,帮助理解。
![ChatGPT-SQL篇(会打字就能学会SQL)插图8 Screenshot 2023-03-20 at 2.40.11 PM.png](https://i.typlog.com/simona/8320705576_295177.png)
how should i think about this question
还是觉得有一点不知道如何下手,那就让ChatGPT一步步拆解。
![ChatGPT-SQL篇(会打字就能学会SQL)插图9 Screenshot 2023-03-20 at 2.41.52 PM.png](https://i.typlog.com/simona/8320705476_288057.png)
how to determine which type of join to use in this question?
在关于JOIN的题目里,决定哪一种JOIN是最重要的一步,我们也可以问ChatGPT。
![ChatGPT-SQL篇(会打字就能学会SQL)插图10 Screenshot 2023-03-20 at 2.45.12 PM.png](https://i.typlog.com/simona/8320705276_887144.png)
select first_name, last_name, department_name, salary from employees join departments on department_id = department_id
这里我又故意给了错误的回答,在department_id前面没有加上table的名字。
ChatGPT就指出了这个错误,并且教我使用aliases。
![ChatGPT-SQL篇(会打字就能学会SQL)插图11 Screenshot 2023-03-20 at 2.48.43 PM.png](https://i.typlog.com/simona/8320705065_630814.png)
在各种练习之后,我们可以开始准备面试了!
can you find a question used by facebook during data engineer interview
![ChatGPT-SQL篇(会打字就能学会SQL)插图12 Screenshot 2023-03-20 at 2.49.55 PM.png](https://i.typlog.com/simona/8320704994_059797.png)
can you give me a more complex question that has been used in data engineer interviews
上面这个问题有一点点太简单啦,我就问有没有更难的问题。
![ChatGPT-SQL篇(会打字就能学会SQL)插图13 Screenshot 2023-03-20 at 2.51.31 PM.png](https://i.typlog.com/simona/8320704898_084246.png)
最后的话来看一下ChatGPT如何辅导Leetcode SQL题目。 我随便找了一道Leetcode database的题目,https://leetcode.cn/problems/second-highest-salary/,复制粘贴给ChatGPT。
![ChatGPT-SQL篇(会打字就能学会SQL)插图14 Screenshot 2023-03-20 at 3.12.55 PM.png](https://i.typlog.com/simona/8320703613_022677.png)
can you explain?
![ChatGPT-SQL篇(会打字就能学会SQL)插图15 Screenshot 2023-03-20 at 3.14.44 PM.png](https://i.typlog.com/simona/8320703505_05631.png)
what if we want to get the Nth highest salary?
![ChatGPT-SQL篇(会打字就能学会SQL)插图16 Screenshot 2023-03-20 at 3.16.44 PM.png](https://i.typlog.com/simona/8320703384_795472.png)
what does 'LIMIT n-1, 1 ' mean?
这里出现了一个新的概念Offset,于是就追问一下。
![ChatGPT-SQL篇(会打字就能学会SQL)插图17 Screenshot 2023-03-20 at 3.18.55 PM.png](https://i.typlog.com/simona/8320703252_930332.png)
总结一下:
上面是我测试如果用ChatGPT来自学SQL的实录。总结一下:
- ChatGPT教得很好;
- SQL最主要的学习方式就是练习以及解题思路,可以让ChatGPT给很多练习题,并且让它给出如何一步步思考的过程;
- 遇到不会写的题目,就拿给ChatGPT吧!