3,通过as给与列别名 :select 列名1as 表名1,列名2 as 别名2.... from 表名;
注:只改变输出时的列名 数据库内不改变
4,去重: select distinct 列名 from 表名;
5,升序 : select * from 表名 order by 列名 asc;
6,降序:select from 表名 order by 列名 desc;
7,分组根据列名相同的放在一起:select * from 表名 group by 列名;
8,条件分组所有满足条件的放一组,其余不管:select id from user group by age having id > 20;
9,查看单前用户: select uaer();
10,查看当前数据库版本:select version();
11,查看当前日期 :select current_date();
12,查看当前时间:select current_ime();
13,查看标准时间:select utc_time;
14,查看当前日期时间:select current_timestamp;
添:
1,添加列全部的内容: insert into 表名 values(id,name ,age....),(id2,name2,age2....)
注:有多少列接要写多少值
2,添加列部分内容: insert into 表名 (id,name) values (id,name),(id2,name2);
注:有默认值可以不写
改:
1,修改指定列的全部值:update 表名 set 列名 = 值
注:可以在后面添加条件语句指定删除部分值
删:
1,删除指定列中全部的值:delete from 表名 列名;
注:可以在后面添加条件语句指定修改部分值
条件语句
1,查询 ,删除, 修改 都可以用有条件语句 , 如果没有则针对整个表
2,where 哪里语句(相当于if满足执行不满足执行) 3,比较: where id = 101 where id > 1 where < 10 4 ,并且(同时满足): where id >1 and id < 10 5, 或者(满足一个即可)where id >10 or id < 2
6,范围 从a 到 b 【a ~b】:where between a and b
7, 选项中有就执行操作 :where int(1,2,3) 选项中有就不执行操作 not int(1,2,3) 8, lile 模糊查询 % 匹配多个 例:select name from user where like '王%' 查询王开头的名字 _ 匹配一个 例:select name from user where like '王_' 王开头两个字的名字 四,类型
on update restrict 拒绝同步更新 on delete restrict 拒绝同步删除
例:create table orders(id int not null auto_increment, uid int not null, gid int not null , num int not null, primary key(id), foreign key(uid) references user(id) on delete cascade on update cascade, foreign key (gid) references goods(id)on delete cascade on update cascade)