SQL常用命令总结(一)

增加

1、在表中插入数据

命令:insert into 表名 (列名 ,列名) values (值,值)
例如:insert into student (name,sex,age,grade) values (‘张三’,113,26)

删除

1、删除表格

命令:drop table 表名
例如:drop table student

修改

1、修改表中的数据

命令:update from 表名 set 列名=新值
例如:update from student set grade=36

查找

1、基础查找表的数据

命令:select 要查询的数据列名(*from 表名 where 筛选条件(无法对分组后的数据进行筛选)
例如:select name fron student where grade<30  //查找分数小于30分的学生名字
例如:select * fron student where grade<30  //查找分数小于30分的所有学生信息

2、高级查找表的数据

命令:select 要查询的数据列名(*from 表名 where 筛选条件 group by 列名(分组)having 筛选条件(只能对分组后的数据进行筛选)order by 排序方式(控制数据最后输出的排列方式有正序:asc、倒叙:desc)】
例如:通过性别分组,sex=1的正序排序后,查找分数小于30分的学生名字
select name fron student where grade<30 [group by sex having sex=1 order by asc]

**多条件查询**
命令:其他相同,where后面的条件用and链接
例如:....... where age=13 and grade=100

3、多个表同时查找(内连接查询)

命令:select 要查询的数据列名(*) from 表名1,表名2 where 筛选条件(例如表名1.列明=表明2.列明)
例如:查找学生表和家长表,找到 学生表里名字跟家长表里的孩子列 对应的数据
select * from student,parent where student.name=parent.child

**使用别名**
命令:select 要查询的数据列名(*) from 表名11别名,表名22别名 where 筛选条件(例如表名1别名.列明=表明2别名.列明)
例如:查找学生表和家长表,找到 学生表里名字跟家长表里的孩子列 对应的数据
select s.name,p.name from student s,parent p where s.name=p.child

4、其他关键字查询(子查询)

**带In关键字的子查询1**
命令:第一个select语句 did in (第二个select语句)
例如:查询父母表里年龄为50岁的人孩子的数据,然后给外层的查询语句使用。
select * from student where did in select child from parent where age=50

**带In关键字的子查询2**
命令:第一个select语句 did not in (第二个select语句)
例如:查询父母表里年龄****50岁的人孩子的数据,然后给外层的查询语句使用。
select * from student where did not in select * from parent where age=50
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值