每日一练--MYSQL

每日一练--MYSQL_第1张图片

自己创建了一个小实验

CREATE TABLE appointment ( 
appointment_id  INT  NOT NULL , 
patient INT NOT NULL,
room VARCHAR(25) NOT NULL
); 
INSERT INTO appointment VALUES(1,101,'A');
INSERT INTO appointment VALUES(2,103,'A');
INSERT INTO appointment VALUES(3,101,'A');
INSERT INTO appointment VALUES(4,101,'A');
INSERT INTO appointment VALUES(5,102,'A');
INSERT INTO appointment VALUES(6,101,'B');
INSERT INTO appointment VALUES(7,102,'A');

SELECT * FROM appointment;
SELECT COUNT(DISTINCT(patient)) 
  FROM appointment
 WHERE room = 'A';

SELECT patient,COUNT(*)
  FROM appointment
 WHERE room = 'A'
 GROUP BY patient;

第一个查询结果:

每日一练--MYSQL_第2张图片

第二个查询结果:

每日一练--MYSQL_第3张图片

 

你可能感兴趣的:(Datawhale之MySQL)