当前位置:网站首页>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
边栏推荐
- 875. Leetcode, a banana lover
- AcWing——第55场周赛
- Acwing: Game 58 of the week
- (POJ - 1458) common subsequence (longest common subsequence)
- The "sneaky" new asteroid will pass the earth safely this week: how to watch it
- Li Kou: the 81st biweekly match
- Chapter 5 namenode and secondarynamenode
- 第7章 __consumer_offsets topic
- Codeforces Round #802(Div. 2)A~D
- Input can only input numbers, limited input
猜你喜欢

第6章 Rebalance详解

Chapter III principles of MapReduce framework

Flag framework configures loguru logstore

QT implementation window gradually disappears qpropertyanimation+ progress bar

第五章 Yarn资源调度器

QT实现窗口渐变消失QPropertyAnimation+进度条

Pull branch failed, fatal: 'origin/xxx' is not a commit and a branch 'xxx' cannot be created from it

Chapter 1 overview of MapReduce

Chapter 6 rebalance details

js封装数组反转的方法--冯浩的博客
随机推荐
(POJ - 3186) treatments for the cows (interval DP)
(POJ - 3258) River hopper (two points)
Codeforces Round #803 (Div. 2)A~C
Date plus 1 day
Codeforces Round #798 (Div. 2)A~D
Anaconda下安装Jupyter notebook
Bisphenol based CE Resin Industry Research Report - market status analysis and development prospect forecast
Investigation report of bench type Brinell hardness tester industry - market status analysis and development prospect prediction
Li Kou - 298th weekly match
Install Jupiter notebook under Anaconda
Base dice (dynamic programming + matrix fast power)
QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)
QT simulates mouse events and realizes clicking, double clicking, moving and dragging
两个礼拜速成软考中级软件设计师经验
Read and save zarr files
Effet d'utilisation, déclenché lorsque les composants de la fonction sont montés et déchargés
Useeffect, triggered when function components are mounted and unloaded
Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)
Spark的RDD(弹性分布式数据集)返回大结果集
树莓派4B64位系统安装miniconda(折腾了几天终于解决)