doc命令操作数据库(下)

1、给数据表添加一组数据:

  

 2、给数据表添加多组数据:

3、对数据进行删除和修改:

4、用select查询单个或多个数据信息:

5、去除重复值:

 6、查询的各种用法:

between的用法:

查询排序:

limit的用法:

分组:

查询总数:

起别名:

select *from 表 where id = 2;

select * from 表 GROUP BY CLASS LIMIT 0,2;

select * from 表 where age > 30 order by chengji desc limit 5,5;

内联:

  select 表1.字段 [as 别名],表n.字段 from 表1 inner join 表2 on 条件;

  select username,name from shop_user inner join shop_goods on shop_user.gid = shop_goods.gids;

  说明:以上方式的inner关键字换成cross同样可以,其实也可以省略 

左链接:

  以坐标为基准

  select 表1.字段 [as 别名],表n,字段 from 表1 left join 表n on 条件;

  select username,name as uname,name as gname from shop_user right join shop_goods on shop _user.gid = shop_goods.gid;

右链接:

  select 表1.字段 [as 别名],表n.字段 from 表1 right join 表n on 条件;

  select username as uname,name as gname from shop_user right join shop_goods on shop_user.gid = shop_goods.gid;

嵌套查询:不推荐使用 效率慢

  select 字段 from 表 where 字段 in(select id form 表);

  select  * from shop user where gid in (select gid from shop_goods);

    

猜你喜欢

转载自www.cnblogs.com/whrTC/p/9309622.html