mysql 分组和排序
mysql> select * from table1;
+----------+------------+-----+---------------------+
| name_new | transactor | pid | order_date |
+----------+------------+-----+---------------------+
| 1hahha | 1xiaohong | | -- :: |
| 2hahha | 2xiaohong | | -- :: |
| 3hahha | 3xiaohong | | -- :: |
| 4hahha | 4xiaohong | | -- :: |
| 3hahha | bob | | -- :: |
| 3hahha | lee | | -- :: |
| 3hahha | lee | | -- :: |
| 3hahha | lee | | -- :: |
| 3hahha | bob | | -- :: |
| 3hahha | bob | | -- :: |
+----------+------------+-----+---------------------+
rows in set (0.00 sec) mysql> select transactor,count(*) as num from table1 where pid >= group by transactor;
+------------+-----+
| transactor | num |
+------------+-----+
| 4xiaohong | |
| bob | |
| lee | |
+------------+-----+
rows in set (0.00 sec) mysql> select transactor,count(*) as num from table1 where pid >= group by transactor with rollup;
+------------+-----+
| transactor | num |
+------------+-----+
| 4xiaohong | |
| bob | |
| lee | |
| NULL | |
+------------+-----+
rows in set (0.00 sec) mysql> select transactor,count(*) as num from table1 where pid >= group by transactor with rollup having num>= order by transactor;
ERROR (HY000): Incorrect usage of CUBE/ROLLUP and ORDER BY mysql> select transactor,count(*) as num from table1 where pid >= group by transactor having num>= order by transactor;
+------------+-----+
| transactor | num |
+------------+-----+
| bob | |
| lee | |
+------------+-----+
rows in set (0.00 sec) mysql> select transactor,count(*) as num from table1 where pid >= group by transactor having num>= order by transactor desc;
+------------+-----+
| transactor | num |
+------------+-----+
| lee | |
| bob | |
+------------+-----+
rows in set (0.00 sec)
mysql 分组和排序的更多相关文章
- mysql 分组内 排序
mysql 分组内 排序 类似于 sqlserver over partition by 因为mysql中木有sqlserver over partition by这个函数,要从sqlserver ...
- mysql分组和排序操作
分组.排序操作 sele ...
- MySQL分组排序(取第一或最后)
MySQL分组排序(取第一或最后) 方法一:速度非常慢,跑了30分钟 SELECT custid, apply_date, rejectrule FROM ( SELECT *, IF ( , ) A ...
- MySQL在按照某个字段分组、排序加序号
事情是这样的,最近领导给了一个新的需求,要求在一张订单表中统计每个人第一次和第二次购买的时间间隔,最后还需要按照间隔统计计数,求出中位数等数据. 由于MySQL不想Oracle那般支持行号.中位数等, ...
- mysql 分组和聚合函数
mysql 分组和聚合函数 Mysql 聚集函数有5个: 1.COUNT() 记录个数(count(1),count(*)统计表中行数,count(列名)统计列中非null数) 2.MAX() 最大值 ...
- Mysql 分组选择
Mysql 分组选择 在其他的数据库中我们遇到分组选择的问题时,比如在分组中计算前10名的平均分 我们可以使用row_number()over() 比较方便的得到. 但是在mysql中,问题就被抛了出 ...
- Mysql高手系列 - 第9篇:详解分组查询,mysql分组有大坑!
这是Mysql系列第9篇. 环境:mysql5.7.25,cmd命令中进行演示. 本篇内容 分组查询语法 聚合函数 单字段分组 多字段分组 分组前筛选数据 分组后筛选数据 where和having的区 ...
- mysql 实现经纬度排序查找功能
需求如下: 商品有多个门店,用户使用App时需要查找附近门店的商品,商品要进行去重分页. 思路: 1.确认mysql自带经纬度查询函数可以使用. 2.该需求需要利用分组排序,取每个商品最近门店的商品i ...
- mysql分组合并GROUP_CONCAT
SELECT pid, GROUP_CONCAT(field ORDER BY coder desc) 'msg'from product_field GROUP BY pid 分 ...
随机推荐
- mysql-配置与使用(跳过原始密码登陆)
目录 简单的使用步骤 环境变量的操作 配置文件的使用 查找进程 mysql 5.6 管理员密码的设置 简单的使用步骤 bin 下面有mysqld.exe 是服务端程序, mysql.exe 是客户端程 ...
- Java 之 JSP
一.JSP 概述 Java Server Pages:java 服务器页面.页面中既可以指定定义 html标签,也可以定义 Java 代码. 二.原理 JSP 本质上就是一个 Servlet. 原理示 ...
- Java 之 Response 对象
Response 对象 一.Response 原理和继承结构 原理和继承结构参考 request. 二.Response 对象 Response 就是用来设置响应消息. 1.设置响应行 响应头格式 ...
- Linux E667 同步失败
在使用Vim编辑/proc目录下的文件后,保存,显示"E667 同步失败" 原因 因为proc这个目录是一个虚拟文件系统,它放置的数据都是在内存中,本身不占有磁盘空间,所以使用Vi ...
- 如何创建SAP Cloud Platform Process Integration runtime服务
登录SAP Cloud Platform cockpit,进入subaccount的Service marketplace界面,选择process integration runtime: 点击ins ...
- php 弹窗案例
<?php // 弹出对话框并且返回原来的页面 echo "<script language=\"JavaScript\">\r\n"; ec ...
- Mysql 单表查询where初识
Mysql 单表查询where初识 准备数据 -- 创建测试库 -- drop database if exists student_db; create database student_db ch ...
- MYSQL使用source命令,导入SQL文件
命令 source D:/student.sql
- python smtp登陆邮箱失败
>>> server.connect('smtp.163.com') (220, b'163.com Anti-spam GT for Coremail System (163com ...
- Docker01-学习环境
目录 安装VMware 安装Ubutu CRT连接Ubutu 设置root密码 安装VMware 下载 VMware-workstation-15 https://dwz.cn/sSAat65l 密码 ...