sql语句的增删改查

1.增 insert   into

insert into thread(tid,username)values(1,'liai');

thread:表格名   thread括号里面是表里面的列名,后面那个括号里面是对应前面要加入的内容

#注意:列与值应该严格对应

2.删 delete

delete from thread where tid=4;

3.改 update

update thread set pubtime=6 where username='lisan';

#注意:where不加会影响所有行

4.查 select

<1>where查询:针对磁盘数据文件

where为表达式,值为真或假

列为变量,变量可以计算

运算符:<   <=   >    >=   ==    !=or<>    in(在集合内)  between(在某范围内)    NOT !    OR ||     AND &&

<1>select * from user;//查user表
<2>select * from thread where tid>=3;//查thread表格中tid>=3那几行(包含全部内容)
<3>select tid,username from thread where tid>=2;查thread表格中tid>=2那几列(包含tid和username)

1>group by:分组与统计函数

avg()平均函数

max()   min()   count()  sum()

例如:
select cat_id,avg(shop_price) from goods group by cat_id;

2>having函数

例如:
select sum(score<60) as gk from result having gk>=2;

3>排序 order by

asc 升序

desc 降序

内部排,直接用“,”连接   by cat_id asc,shop_price desc;

4>limit:限制取出条目数

limit 0,5;  0--->偏移量   5---->取出条目数

<2>模糊查询

like '...%';

not like '...';

查空    where name is (not) NULL;

<3>from查询与exists查询

<4>新手1+N查询:1条语句->N条数据->N条查询

<5>内连接查询:select xxxx from boy inner join girl on  条件

       来自两张表

<6>左连接查询:



select table a left join table b on a.id = b.ta_id**

(左边都查出来)

      右连接查询:



select table a right join table b on a.id = b.ta_id**

(右边都查出来)

<7>union查询:合并(条件:各语句取出列数相同)

注意:使用时完全相等行将会被合并 可以使用union all

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值