SQL数据库——查询
前期准备,建造练习用数据库
create database python_test charset=utf8;
use python_test;
select database();
create table students(
id int unsigned primary key auto_increment not null,
name varchar(20) default " ",
age tinyint unsigned default 0,
height decimal(5, 2),
gender enum("男", "女", "中性", "保密") default "保密",
cls_id int unsigned default 0,
is_delete bit default 0
);
create table classes(
id int unsigned auto_increment primary key not null,
name varchar(30) not null);
insert into students values
(0, "小明", 18, 180.00, 2, 1, 0),
(0, "小月月", 18, 180.00, 2, 2, 1),
(0, "彭于晏", 29, 185.00, 1, 1, 0),
(0, "刘德华", 59, 175.00, 1, 2, 1),
(0, "黄蓉", 38, 160.00, 2, 1, 0),
(0, "凤姐", 28, 150.00, 4, 2, 1),
(0, "王祖贤", 18, 172.00, 2, 1, 1),
(0, "周杰伦", 36, NULL, 1, 1, 0),
(0, "程坤", 27, 181.00, 1, 2, 0),
(0, "刘亦菲", 25, 166.00, 2, 2, 0),
(0, "金星"