Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

MySQL: หานักเรียนที่คะแนนมากกว่าค่าที่กำหนด ด้วย WHERE


กรองนักเรียนที่คะแนนมากกว่าค่าที่กำหนด ใช้ WHERE เงื่อนไข

ตัวอย่าง

mysql> CREATE TABLE DemoTable (
    -> Id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    -> StudentName VARCHAR(100),
    -> StudentScore INT
    -> );
mysql> INSERT INTO DemoTable(StudentName, StudentScore) VALUES
    -> ('John',43), ('Sam',48), ('Chris',33), ('Robert',89);

ข้อมูล

+----+-------------+--------------+
| Id | StudentName | StudentScore |
+----+-------------+--------------+
| 1  | John        | 43           |
| 2  | Sam         | 48           |
| 3  | Chris       | 33           |
| 4  | Robert      | 89           |
+----+-------------+--------------+

Query: คะแนน > 45

mysql> SELECT StudentName FROM DemoTable WHERE StudentScore > 45;

ผลลัพธ์ (Sam และ Robert)

+-------------+
| StudentName |
+-------------+
| Sam         |
| Robert      |
+-------------+