GPT Chat Prompts สำหรับการทำงานกับ SQL

1. สร้างฐานข้อมูลและตารางใหม่

คำอธิบาย: ใช้ prompt นี้เพื่อให้ GPT ช่วยสร้างคำสั่ง SQL ในการสร้างฐานข้อมูลและตารางใหม่

Prompt:

Create a SQL database named 'Library' and a table called 'Books' with columns for BookID, Title, Author, Genre, and PublishedYear.

2. เขียนคำสั่ง SELECT เบื้องต้น

คำอธิบาย: ใช้ prompt นี้เพื่อดึงข้อมูลจากตารางที่กำหนด

Prompt:

Write a SQL query to select all records from the 'Employees' table.

3. กรองข้อมูลด้วยเงื่อนไข

คำอธิบาย: ใช้ prompt นี้เพื่อดึงข้อมูลที่ตรงตามเงื่อนไขเฉพาะ

Prompt:

Write a SQL query to select the Name and Salary of employees from the 'Employees' table where Salary is greater than 60000.

4. การใช้ JOIN เพื่อรวมข้อมูลจากหลายตาราง

คำอธิบาย: ใช้ prompt นี้เพื่อรวมข้อมูลจากสองตารางโดยใช้ความสัมพันธ์ระหว่างตาราง

Prompt:

Write a SQL query to join the 'Orders' and 'Customers' tables on CustomerID and select the OrderID, OrderDate, and CustomerName.

5. การจัดกลุ่มข้อมูลและการใช้ฟังก์ชัน Aggregate

คำอธิบาย: ใช้ prompt นี้เพื่อจัดกลุ่มข้อมูลและใช้ฟังก์ชันเช่น COUNT, SUM, AVG

Prompt:

Write a SQL query to find the total number of orders for each customer in the 'Orders' table.

6. การอัปเดตข้อมูลในตาราง

คำอธิบาย: ใช้ prompt นี้เพื่อปรับปรุงข้อมูลในตารางที่มีอยู่

Prompt:

Write a SQL query to update the Salary of the employee with EmployeeID 5 to 75000 in the 'Employees' table.

7. การลบข้อมูลจากตาราง

คำอธิบาย: ใช้ prompt นี้เพื่อลบข้อมูลที่ไม่ต้องการจากตาราง

Prompt:

Write a SQL query to delete records from the 'Employees' table where the Position is 'Intern'.

8. การสร้างมุมมอง (View)

คำอธิบาย: ใช้ prompt นี้เพื่อสร้างมุมมองที่ซับซ้อนจากข้อมูลในตารางต่างๆ

Prompt:

Create a SQL view named 'HighEarners' that includes Name and Salary from the 'Employees' table where Salary is above 70000.

9. การใช้ Subquery

คำอธิบาย: ใช้ prompt นี้เพื่อสร้างคำสั่ง SQL ที่มีคำสั่งย่อยภายใน

Prompt:

Write a SQL query to find the names of employees who have a salary higher than the average salary in the 'Employees' table.

10. การจัดทำดัชนี (Index)

คำอธิบาย: ใช้ prompt นี้เพื่อสร้างดัชนีเพื่อเพิ่มประสิทธิภาพการค้นหาข้อมูล

Prompt:

Create an index on the 'LastName' column in the 'Employees' table to improve search performance.