当前位置:网站首页>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
边栏推荐
- 第一章 MapReduce概述
- Anaconda下安装Jupyter notebook
- Acwing: the 56th weekly match
- Market trend report, technological innovation and market forecast of desktop electric tools in China
- Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)
- QT realizes window topping, topping state switching, and multi window topping priority relationship
- Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
- Specify the format time, and fill in zero before the month and days
- Problem - 922D、Robot Vacuum Cleaner - Codeforces
- QT模拟鼠标事件,实现点击双击移动拖拽等
猜你喜欢

Chapter 5 detailed explanation of consumer groups

QT实现圆角窗口

拉取分支失败,fatal: ‘origin/xxx‘ is not a commit and a branch ‘xxx‘ cannot be created from it

QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)

QT realizes window topping, topping state switching, and multi window topping priority relationship

第五章 Yarn资源调度器

第2章 HFDS的Shell操作

Kubernetes cluster deployment

使用jq实现全选 反选 和全不选-冯浩的博客

业务系统兼容数据库Oracle/PostgreSQL(openGauss)/MySQL的琐事
随机推荐
< li> dot style list style type
拉取分支失败,fatal: ‘origin/xxx‘ is not a commit and a branch ‘xxx‘ cannot be created from it
解决Intel12代酷睿CPU【小核载满,大核围观】的问题(WIN11)
第6章 Rebalance详解
Spark的RDD(弹性分布式数据集)返回大结果集
力扣——第298场周赛
Research Report on market supply and demand and strategy of double drum magnetic separator industry in China
Input can only input numbers, limited input
Codeforces Round #798 (Div. 2)A~D
Codeforces Round #803 (Div. 2)A~C
Chapter 6 rebalance details
Spark独立集群动态上线下线Worker节点
Market trend report, technological innovation and market forecast of double door and multi door refrigerators in China
Investigation report of bench type Brinell hardness tester industry - market status analysis and development prospect prediction
Problem - 1646C. Factorials and Powers of Two - Codeforces
解决Intel12代酷睿CPU单线程调度问题(二)
Kubernetes cluster deployment
js封装数组反转的方法--冯浩的博客
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
Is the sanic asynchronous framework really so strong? Find truth in practice