Computer >> Máy Tính >  >> Lập trình >> MySQL

Tìm hiểu hồ sơ của sinh viên có nhiều hơn một điểm cụ thể trong MySQL?


Đặt nó bằng WHERE và nhận hồ sơ của học sinh nhiều hơn một số điểm cụ thể. Đầu tiên chúng ta hãy tạo một bảng -

mysql> create table DemoTable
   -> (
   -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> StudentName varchar(100),
   -> StudentScore int
   -> );
Query OK, 0 rows affected (1.65 sec

Chèn một số bản ghi vào bảng bằng lệnh chèn -

mysql> insert into DemoTable(StudentName,StudentScore) values('John',43);
Query OK, 1 row affected (0.81 sec)

mysql> insert into DemoTable(StudentName,StudentScore) values('Sam',48);
Query OK, 1 row affected (0.12 sec)

mysql> insert into DemoTable(StudentName,StudentScore) values('Chris',33);
Query OK, 1 row affected (1.50 sec)

mysql> insert into DemoTable(StudentName,StudentScore) values('Robert',89);
Query OK, 1 row affected (0.27 sec)

Hiển thị tất cả các bản ghi từ bảng bằng câu lệnh select -

mysql> select *from DemoTable;

Đầu ra

Điều này sẽ tạo ra kết quả sau -

+----+-------------+--------------+
| Id | StudentName | StudentScore |
+----+-------------+--------------+
|  1 | John        | 43           |
|  2 | Sam         | 48           |
|  3 | Chris       | 33           |
|  4 | Robert      | 89           |
+----+-------------+--------------+
4 rows in set (0.00 sec)

Sau đây là truy vấn để lấy hồ sơ của những học sinh có điểm trên 45 điểm -

mysql> select StudentName from DemoTable where StudentScore > 45;

Đầu ra

Điều này sẽ tạo ra kết quả sau -

+-------------+
| StudentName |
+-------------+
| Sam         |
| Robert      |
+-------------+
2 rows in set (0.00 sec)