BETANền tảng này đang được phát triển tích cực; có thể có lỗi, thiếu tính năng và nguy cơ mất dữ liệu. Cảm ơn bạn đã ủng hộ!

SQL

Học bằng cách chơi

Trả lời những câu hỏi này để kiếm năng lượng, rồi câu cá và khám phá. Không cần tài khoản.

Dành cho giáo viên: slide bài học, ghi chú ôn tập, sơ đồ sẵn dùng cho SQL (Computer Science, CIE) — dùng trong bài giảng của bạn, hoặc chạy chủ đề như một hoạt động lớp học tương tác để học sinh chơi như một trò chơi trực tiếp.

Ghi chú bài học

What is SQL?

  • SQL (Structured Query Language) is a programming language used to interact with a DBMS.
  • SQL allows users to select, order, sum, and count data.

SELECT and FROM

  • SELECT retrieves data from a database table.
  • Use `SELECT×` to retrieve all columns from a table.
  • FROM specifies the table(s) to retrieve data from.
  • Example: `SELECT name, age FROM users;` retrieves names and ages from the 'users' table.

WHERE Clause

  • WHERE filters data based on a specified condition.
  • Example: `SELECT×FROM users WHERE age > 30;` retrieves users older than 30.
  • Conditions can use comparison operators: `=`, `>`, `<`, `≥`, `≤`, `<>`.

AND and OR Operators

  • AND combines multiple conditions – all must be true.
  • Example: `SELECT×FROM users WHERE age > 18 AND city = 'New York';`
  • OR retrieves data when at least one condition is true.
  • Example: `SELECT×FROM users WHERE age < 18 OR city = 'New York';`

Wildcards and LIKE

  • Wildcard `%` matches any sequence of characters.
  • Use LIKE with wildcards for pattern matching.
  • Example: `SELECT×FROM users WHERE name LIKE 'J%';` finds names starting with 'J'.
  • `×` selects all columns; `%` is used only with LIKE.

ORDER BY

  • ORDER BY sorts results in ascending (ASC) or descending (DESC) order.
  • Default order is ascending.
  • Example: `SELECT Forename, Lastname FROM Students ORDER BY Lastname ASC;`
  • Multiple columns can be specified, e.g., `ORDER BY Lastname, Forename ASC`.

SUM and COUNT

  • SUM adds up and outputs the sum of a numeric field.
  • Example: `SELECT SUM(Salary) FROM tblpeople;`
  • COUNT counts the number of rows that match the criteria.
  • Example: `SELECT COUNT(×) FROM tblpeople WHERE Salary > 50000;`

Worked Example

  • Given table `tblanimals` with fields: Animal, Breeding, Number of Young.
  • To display animals that are breeding and have exactly 1 young:
  • `SELECT Animal FROM tblanimals WHERE Breeding = 'Yes' AND Number of Young = 1;`

Structure of a SQL SELECT query showing the order of clauses.

SQL Query StructureSELECT column1, column2FROM table_nameWHERE conditionORDER BY column ASC|DESCClauses are written in this order

Slide

Sign up free to view the lesson slides

Step through every slide for this topic — plus flashcards and revision notes — with a free account.

Câu hỏi luyện tập

Xem trước miễn phí — 8 trên 53 câu hỏi. Đăng ký để xem tất cả.
  1. 1.What does SQL stand for?

    Easy
    • AStructured Query Language
    • BSimple Query Language
    • CStandard Query Language
    • DSequential Query Language
  2. 2.Which SQL command is used to retrieve data from a database table?

    Easy
    • ASELECT
    • BFROM
    • CWHERE
    • DGET
  3. 3.In SQL, which keyword is used to filter records based on a condition?

    Easy
    • AWHERE
    • BIF
    • CFILTER
    • DHAVING
  4. 4.What does the '×' symbol represent in SQL?

    Easy
    • AAll columns
    • BAll rows
    • CA wildcard character
    • DMultiplication
  5. 5.Which SQL statement retrieves the name and age of all customers from the 'Customers' table?

    Easy
    • ASELECT name, age FROM Customers;
    • BSELECT name AND age FROM Customers;
    • CSELECT×FROM Customers;
    • DGET name, age FROM Customers;
  6. 6.What is the purpose of the ORDER BY clause in SQL?

    Easy
    • ATo sort the result set
    • BTo filter records
    • CTo group records
    • DTo count records
  7. 7.Which SQL function is used to calculate the total of a numeric column?

    Easy
    • ASUM
    • BCOUNT
    • CTOTAL
    • DADD
  8. 8.Given a table 'Students' with columns 'Name' and 'Age', which SQL statement selects students older than 18?

    Easy
    • ASELECT×FROM Students WHERE Age > 18;
    • BSELECT×FROM Students IF Age > 18;
    • CSELECT×FROM Students HAVING Age > 18;

Unlock all 53 questions & more

Tạo tài khoản miễn phí để xem mọi câu hỏi, slide, thẻ ghi nhớ và ghi chú ôn tập cho chủ đề này.

Đề thi cũ

Luyện đề thi cũ cho chủ đề này sắp ra mắt.
Sắp ra mắt