mysql

1、建库:create database if not exists 库名 default charset utf8;或create database表名  

建表(例):

create table if not exists cs_user(
id int primary key auto_increment,
username varchar(20) not null unique,
password varchar(20) not null,
gender varchar(5) not null,
age int not null
);

2、增:insert into cs_user(username,password,gender,age)values("一","123456","男",17),("二","123456","男",19);

删:delete from cs_user where username="一";删除某一条数据         drop table cs_user;删除表

查:select * from cs_user;查询所有数据      select * from cs_user where username="一";查询某条数据

改:update cs_user set password="111" where username="一";

3、表关联查询:

#内连接w.id和a.site_id的数相同的一行数据合并
select * from websites w INNER JOIN access_log a ON w.id=a.site_id;
#左连接 left join...on 是指内连接后左表多余的部分的数据
select * from websites w LEFT JOIN access_log a ON w.id=a.site_id;
#右连接 left join...on
select * from websites w RIGHT JOIN access_log a ON w.id=a.site_id;
#全连接=左连接 union 右连接
#这里是内连接+左连接+右连接 union去重,union all不去重
select * from websites w left join access_log a on w.id=a.site_id
union
select * from websites w right join access_log a on w.id=a.site_id;

4、子查询

select * from teacherinfo where year(birthday) in (select  year(birthday) from teacherinfo where name='夏老师');查询所有与夏老师同一年出生的教师信息

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值