数据库操作前的准备
-- 创建数据库
-- create database python_test_1 charset=utf8;
-- 使用数据库
-- use python_test_1;
-- students表
-- 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
-- );
-- classes表
-- create table classes (
-- id int unsigned auto_increment primary key not null,
-- name varchar(30) not null
-- );
-- 查询
-- 查询所有字段
-- select * from 表名;
select * from students;
-- 查询指定字段
-- select 列1,列2,... from 表名;
select name,age from students;
-- 使用 as 给字段起别名
-- select 字段 as 名字.... from 表名;
select name as "姓名" , age from students;
-- select 表名.字段 .... from 表名;
select students.name,students.age from students;
-- 可以通过 as 给表起别名
-- select 别名.字段 .... from 表名 as 别名;
select s.name ,s.age from students as s;
-- 消除重复行(查性别)
-- distinct 字段
select distinct gender from students;
-- 条件查询
-- 比较运算符
-- select .... from 表名 where .....
-- >
-- 查询年纪大于18岁的信息
select * from students where age > 18;
-- <
-- 查询年纪小于18岁的信息
select * from students where age < 18;
-- >=,<=
-- 查询小于或者等于18岁的信息
selec * tfrom students where age <= 18;