ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

sql 语句

2022-05-16 00:31:45  阅读:168  来源: 互联网

标签:语句 profile gender university user sql where select


SELECT DISTINCT 表示查询结果中,去掉了重复的行 Distinct表示去掉重复的行

limit offset: 一起使用时,limit表示要取的数量,offset表示跳过的数量

select device_id from user_profile limit 2 offset 0 // 跳过0条,从第一条数据开始取,取两条数据 ---运行效率中

select device_id as user_infors_example from user_profile limit 0,2;
这里主要是用到了 起别名关键字 as 以及组合限制查询 limit 索引,个数
其中as可以省略,索引为0可以省略

as表头重命名 select count(gender) as male_num

2、计数:count函数

3、保留小数位数:round(列名,位数)

4、求平均数:avg函数

select count(gender) as male_num,round(avg(gpa),1)as avg_gpa from user_profile where gender='male'

完整sql:

select count(male) as male_num, round(avg(gpa),1) as avg_gpa from user_profile where gender='male'

条件查询案列(where)

select device_id,university from user_profile where university='北京大学';
更具需求,首先知道要北京大学的学生,条件查询案列(where)所有用条件university='北京大学'

1.between 在列值得某与某之间
select
device_id,
gender,
age,
university
from user_profile
WHERE
age between 20 and 23

where约束

where字句中可以使用:

  1. 比较运算符:> >= < <= <> !=
  2. between 80 and 100——值在80到100之间
  3. in(80,90,100)——值是80或90或100
  4. like 'e%' 通配符可以是%或_, %表示任意多字符 _表示一个字符(select device_id,age,university from user_profile where university like '%北京%')
  5. 逻辑运算符:在多个条件直接可以使用逻辑运算符 and or not

两者关系是或,所以用or

select device_id,gender,age,university,gpa from user_profile where university ="北京大学" or gpa >3.7

 GROUP BY

 

 

标签:语句,profile,gender,university,user,sql,where,select
来源: https://www.cnblogs.com/LLW521/p/16275409.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有