SQL 新人入门 (从基础框架走起)
来源:互联网 发布:云进销存软件哪个好 编辑:程序博客网 时间:2024/06/02 02:06
SQL 新人入门 (从基础框架走起)SQL语句最基础框架
select 字段 from 表名
以下语句皆在该基础上加内容,假设表名为table
①如果想搜索表内所有内容
select * from table
②搜索多个字段
select city,country from table
③同时搜索两个表的内容,假设两个表里id字段内容相同
select a.city,a.country, b.numberfrom table1 aleft join table2 bon a.id=b.id
④以city分组
select a.city,a.country, b.numberfrom table afrom table bgroup by city
⑤以city升序排序
select a.city,a.country, b.numberfrom table afrom table bgroup by cityorder by city
降序
select a.city,a.country, b.numberfrom table afrom table bgroup by cityorder by city desc
⑥类似数据透视表功能,计算城市数量
select a.city,a.country, b.number,count(1) //括号里面的1代表以第一列为计数标准。from table afrom table bgroup by cityorder by city
⑦计算数量的基础上去重
select a.city,a.country, b.number,count(distinct positionId) //distinct 后面跟具有唯一标识,可用来做去重标准from table afrom table bgroup by cityorder by city
⑧多维聚合
select a.city,a.country, b.number,count(distinct positionId) from table afrom table bgroup by city,country //group by 添加多个字段,它将以多维的形式进行数据聚合order by city
⑨限制条件,数量500以上的城市
select a.city,count(distinct positionId) from table agroup by city having count(distinct positionId) >= 500 order by city
⑩嵌套子查询
select * from(select city ,count (distinct positionId) as counts from tablegroup by city ) as t1 //as 可命名表名where counts >=500
阅读全文
0 0
- SQL 新人入门 (从基础框架走起)
- 后台框架,走起
- python零基础走起
- 从基础学起
- 要从基础学起..
- 从今天起,我的人生走直线
- C编译器剖析_2.1 从Makefile走起
- 从算法学起C语言--老鼠走迷宫
- 慢慢数据抓取路,从BeautifulSoup走起
- 2.Java学习框架(零基础学起)
- golang走起(四)执行命令行
- Beego走起(一) 初步认识
- golang 走起(六) 超时
- golang 走起(七) 多态
- golang 走起(八) 目录结构
- Lua简明入门实践(从"基"搞起)_(二)Lua基础语法
- 零基础入门-javaScript学习笔记之从基本数据类型学起
- 入门黑客从哪里学起
- 语音算法工程师
- 【老坑】斐波那契钟计划
- JSON知识点一FastJSOn
- Python(5)使用for...in循环和列表推导式打印一个99乘法表
- 南阳理工OJ-题目463-99乘法表
- SQL 新人入门 (从基础框架走起)
- 无穷小和无穷大·漫画
- mysql-5.7.20-winx64忘记密码
- 面向对象程序设计上机练习二(函数模板)
- kuangbin专题五 并查集 POJ2912 Rochambeau
- 52. N-Queens II
- 171213之项目错误总结3
- SQL 、MySql 查询前几年、几天、几小时的数据
- vlan是什么?怎么创vlan?