mysql实用篇

本文介绍了SQL的基本操作,包括在test数据库下创建名为student的表,插入、更新和查询数据。讨论了别名使用、排序方式、条件查询以及模糊查询的方法。还涉及到了多表查询,如交叉连接、左连接和右连接的概念及其示例。
摘要由CSDN通过智能技术生成

创建一个基本的表

create table student(id int not null,name char(10));

创建表之前选择在哪个数据库下面建表

use test

在新建的表里面插入一条数据

insert  into student  values(1,"李木")

修改数据

update  student set name="看个屁" where id=2

基本查询语法

select * from student where id=1

别名字段
别名字段会吧查询结果变为别名,实用
在这里插入图片描述
别名表

select id,name as "姓名" from student as s

排序
asc表示字段按升序排序;desc表示字段按降序排序。其中asc为默认值,排序不需要where

select * from student order by id desc

条件查询
id在0-1之前,包含0和1

select * from student where id  between 0 and 1
select * from student where id  between 1 and 2 and name="李木"

模糊查询
查询字段字符中间有“个”字的数据

select * from student where name like "%个%"

查询字段末尾有‘屁’字的数据

select * from student where name like "%屁"

查询字段以‘李’开头的数据

select * from student where name like "李%"

多表查询
交叉连接

select * from table1 ,table2 

左连接
左连接是已左边表中的数据为基准,若左表有数据右表没有数据,则显示左表中的数据右表中的数据显示为空。

右连接是左向外连接的反向连接,将返回右表的所有行。如果右表的某行在左表中没有匹配行,则将为左表返回空值。

select * from tb_student as st left join tb_score as sc on st.studentNo=so.studentNo;

右连接

select * from tb_student as st right join tb_score as sc on st.studentNo=so.studentNo;
  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

亚索不会吹风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值