sql语句听课笔记

本文介绍了SQL的基础操作,包括查询、插入、更新和删除等基本语法,并解释了如何使用条件语句、聚合函数以及排序和限制结果集的方法。

sql语句入门

查询语句

  • select 字段,字段 from 表名:
    例如:select ‘name’ from Dataset
    表名或字段名加上‘’ 会加快sql语句的执行速度
  • select * 表示搜寻所有数段
    例如:select * from ‘ sss’ where ‘id=2’
    不等于!= 和 <> 等价
    • 条件判断 > , < ,<= ,>=
  • in 的使用
    例如select * from ’ ss’ where ‘id’ in (1,2,4) 查询ss表中的值在()里面的数据
    • not in
  • between的使用
    例如select * from ‘ss’ where ‘id’ between 2 and 4
    select * from ‘ss’ order by ‘time’ desc
    按照时间的降序排序
    • desc降序
    • asc升序
  • order by 语句需要在where的后面
  • limit 限制条数
    例如 select * from ‘aa’ where ‘ID’ in(1,3,4)order by desc limit 0,2
    只查找前两行

count

  • select count(*) from ’ ss’
    查询表中总的数据条数
    • select count(*) as pp from ‘ss’
      通过as语句取别名pp

max(min、average)

  • select max9(id) from ‘ss’’
    查询ss表中id最大的值

添加

insert into 表名(字段名,字段名,—) value (值,值,----)

修改

update 表名 set 字段=值 ······ where 条件
例如 update ‘ss’’ set ‘name’=‘user’,‘pwd’=‘2’

删除

delet from 表名 where 条件
例如 delete from ‘ss’ where ‘id’= ‘name’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值