SQL语句的基本使用1.0



SQL语句的基本使用

  1. 我们要学会使用查询关键字select(这里给大家提醒一下SQL语句是不区分大小写的哦)+要查询的内容(如果要查询全部内容用*)比如姓名:name,等等)+from+表名  来查询表中的所有数据,以上就是基本用法

  2. 接下介绍如何修改查询选项的名称

       select name as 这是修改后的名字  form books

  3. where的使用 

       这个词呢我通常理解为选项或者叫执行条件,请看:

    select name as "书 名" from books--别名中有空格的情况

    select

    id,name,stock,publishedby

    from

    books

    where

    id=5   >,<,<=,>=,!=,<>

    这里的where就作为查询的执行条件使用的,很好理解的

    还可以这样

      where

    id=3 or id=7 or id=8

    或者

         where

    id in (3,7,8)

    还有同时满足多个条件

     

       where

    id>3 and stock <10

  4. sql中使用单引号来表示字符串

     select *

    from books

    where name='妈妈'

  5. 模糊查询使用_匹配单个字符,使用%匹配若干个字符

      select *

    from books

    where name like '_' //where name like_%

    6.查询结果以price(价格)的升序排序,降序把asc改为desc

      select *

    from books

    where id >3

    order by price asc (升序)

  6. 计数

     select count(id)

    from books

    7.平均值,总和

     select avg(price),sum(price)

    from books

    8.去重

     select distinct(publishedby)

    from books

    9.显示部分结果,第一个参数是从第几个开始(下标从0开始),第二个参数是显示多少个数据。

      select *

    from books

    limit 3,3

  1. 10.使用group by把结果进行分组

       select count(id),publishedby

    from books

    group by publishedby(出版社)

    11.使用having来筛选group by 的某个组

    select avg(price),sum(price),publishedby

    from books

     

    group by publishedby

    having publishedby = '人民出版社'

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值