#CREATE database lianxi; #创建数据库
use lianxi;
CREATE table customer(id VARCHAR(30),age int,name VARCHAR(30),birthday date); #创建表
show tables;
insert into customer(id ,age,name,birthday) values('01','18','小马','98-08-28');
insert into customer(id ,age,name,birthday) values('02','18','小雄','98-10-09');
insert into customer(id ,age,name,birthday) values('03','18','小李','98-01-01');
select * from customer; # 表中的所有记录
update customer set age = '19', name = '小李' where id='03' #修改记录
select * from customer; # 表中的所有记录
#删除记录: delete from 表名 where ….
SELECT id,name from customer ;#查询特定的列
SELECT id,name from customer where id>1; #对查询的数据进行过滤
SELECT id,name from customer where id>1 and id<3;
SELECT id,name from customer where id in (2,3);
SELECT id,name from customer where id between 2 and 3;
SELECT id,name from customer where like '_%';
SELECT id,name from customer where age is null;
#查询 age 为 空 的所有人的信息
SELECT * from customer order by age;#排序
select * from customer;
SELECT * from customer order by age desc #降序排序
SELECT id AS xuhao, age nianling FROM customer; #列的别名,
#可以在列名和别名之间加入关键字‘AS’,或者不需要加
describe customer; #显示表结构
desc customer; #查看表结构
03表查询
最新推荐文章于 2024-10-08 11:31:42 发布