当前位置:网站首页>SQL快速入门
SQL快速入门
2022-07-06 09:29:00 【狗蛋儿l】
基础查询
查询多列
查询所用语句 SELECT 字段名 FROM 表名;
答案
select device_id, gender, age, university from user_profile;
查询所有列
*号是选取所有列名
答案:
SELECT * FROM user_profile
简单处理查询结果
查询结果去重
去重查询DISTINCT 要放到列名的前面
答案:
SELECT DISTINCT university FROM user_profile
查询结果限制返回行数
LIMIT显示前面两行。
答案:
SELECT device_id FROM user_profile LIMIT 0,2;
将查询后的列重新命名
改变列标题(取别名) 语法: 列名 | 表达式 [ AS ] 新列名 或: 新列名=列名 | 表达式
答案:
SELECT device_id as user_infors_example
from user_profile
LIMIT 2
条件查询
基础排序
通过order by 进行排序:
asc : 升序
desc : 降序
答案:
select device_id,age
from user_profile
order by age asc;
查找后多列排序
答案:
SELECT device_id, gpa, age
FROM user_profile
ORDER BY gpa, age;
查找后降序排列
答案:
select device_id,gpa,age
FROM user_profile
ORDER BY gpa desc,age desc
基础操作符
查找学校是北大的学生信息
在where条件中增加条件为‘北京大学’即可。
答案:
select device_id,university
from user_profile
where university='北京大学'
查找年龄大于24岁的用户信息
答案:
select device_id,gender,age,university from user_profile
where age>24
查找某个年龄段的用户信息
确定范围 用BETWEEN…AND 和 NOT BETWEEN…AND是逻辑运算符,可以用来查找属性值在或不在指定范围内的元组,其中BETWEEN后边指定范围的下限,AND后边指定范围的上限。BETWEEN…AND…的格式为:列名 | 表达式 [ NOT ] BETWEEN 下限值 AND 上限值
答案:
select device_id,gender,age
FROM user_profile
WHERE age>=20 and age<=23
查找除复旦大学的用户信息
答案:
select device_id, gender, age, university
from user_profile
where university != '复旦大学'
用where过滤空值练习
答案:
SELECT `device_id`,`gender`,`age`,`university`
from user_profile
where not age is NULL
边栏推荐
- Input can only input numbers, limited input
- Spark的RDD(弹性分布式数据集)返回大结果集
- Specify the format time, and fill in zero before the month and days
- Raspberry pie 4B installation opencv3.4.0
- Kubernetes cluster deployment
- Research Report on market supply and demand and strategy of China's tetraacetylethylenediamine (TAED) industry
- 提交Spark应用的若干问题记录(sparklauncher with cluster deploy mode)
- Codeforces Round #799 (Div. 4)A~H
- 浏览器打印边距,默认/无边距,占满1页A4
- Submit several problem records of spark application (sparklauncher with cluster deploy mode)
猜你喜欢
树莓派4B64位系统安装miniconda(折腾了几天终于解决)
本地可视化工具连接阿里云centOS服务器的redis
Submit several problem records of spark application (sparklauncher with cluster deploy mode)
业务系统从Oracle迁移到openGauss数据库的简单记录
QT implementation fillet window
Click QT button to switch qlineedit focus (including code)
QT模拟鼠标事件,实现点击双击移动拖拽等
第2章 HFDS的Shell操作
Browser print margin, default / borderless, full 1 page A4
Spark独立集群动态上线下线Worker节点
随机推荐
QT模拟鼠标事件,实现点击双击移动拖拽等
原生js实现全选和反选的功能 --冯浩的博客
AcWing:第58场周赛
Market trend report, technical innovation and market forecast of double-sided foam tape in China
QT implementation fillet window
Codeforces - 1526C1&&C2 - Potions
Useeffect, triggered when function components are mounted and unloaded
Study notes of Tutu - process
QT implementation window gradually disappears qpropertyanimation+ progress bar
OneForAll安装使用
Research Report on market supply and demand and strategy of double drum magnetic separator industry in China
Codeforces Round #801 (Div. 2)A~C
Market trend report, technological innovation and market forecast of double door and multi door refrigerators in China
Click QT button to switch qlineedit focus (including code)
图像处理一百题(11-20)
CMake Error: Could not create named generator Visual Studio 16 2019解决方法
Market trend report, technological innovation and market forecast of desktop electric tools in China
Spark的RDD(弹性分布式数据集)返回大结果集
useEffect,函數組件掛載和卸載時觸發
解决Intel12代酷睿CPU单线程只给小核运行的问题