当前位置:网站首页>GBase8s数据库select有ORDER BY 子句3
GBase8s数据库select有ORDER BY 子句3
2022-06-29 11:28:00 【爱吃萝卜冰冰凉】
按 CASE 表达式排序
ORDER BY 子句可包括 CASE 表达式来指定排序键。
在下列示例中,表 tab_case 的列 a_col 为 INT 类型。对表 tab_case 的查询包括 Projection
列表中的列 a_col 和聚集表达式 SUM(a_col),并通过 a_col 的值将结果分组。ORDER BY 子句
指定两个排序键:
紧跟在 ORDER BY 关键字之后的 CASE 表达式
• AVG(a_col) 聚集表达式:
CREATE TABLE tab_case(a_col INT, b_col VARCHAR(32));
SELECT a_col, SUM(a_col)
FROM tab_case
GROUP BY a_col
ORDER BY CASE
WHEN a_col IS NULL
THEN 1
ELSE 0 END ASC,
AVG(a_col);
在此,ASC 关键字显式地将 CASE 表达式的结果标识为升序排序键。在缺省情况下,AVG(a_col)
排序键也指定升序排序。
在下列类似的示例中,基于同一 tab_case 表上的查询,第二个 CASE 表达式返回或者 1 或者 0
作为返回的 AVG(a_col) 聚集值的排序键值。
SELECT a_col, SUM(a_col)
FROM tab_case GROUP BY a_col
ORDER BY CASE
WHEN a_col IS NULL
THEN 1
ELSE 0 END ASC,
AVG(a_col),
CASE
WHEN AVG(a_col) IS NULL
THEN 1
ELSE 0 END;
边栏推荐
- 2022年资料员-岗位技能(资料员)操作证考试题库及模拟考试
- c# 键盘钩子
- Win11 web version
- 易快报:我们用 Zadig 实现万次构建部署,聪明运维,释放开发生产力
- mysql截取字符串去重,mysql 截取字符串 去重 拼接
- 恒泰证券开户安全吗 证券排名
- 杰理之关于 TWS 配对方式配置【篇】
- 哈希Hash竞猜游戏系统开发详解技术丨哈希竞猜游戏系统开发方案解析
- &4 express框架
- Record once MSI notebook ge63 plays webpage video flash screen and randomly turns green to solve the problem
猜你喜欢

面试突击61:说一下MySQL事务隔离级别?

Imile uses Zadig's multi cloud environment to deploy thousands of times a week to continuously deliver global business across clouds and regions

杰理之关于 TWS 交叉配对的配置【篇】

RepOptimizer: 其实是RepVGG2

杰理之关于 TWS 声道配置【篇】

Unified exception reporting practice based on bytecode

Meichuang was selected as one of the first member units of the "business security promotion plan" of the ICT Institute

Ttchat x Zadig open source co creates helm access scenarios, and environmental governance can be done!

助力极致体验,火山引擎边缘计算最佳实践

Wonderful! Miaoying technology fully implements Zadig to help container construction, and fully embraces kubernetes and Yunyuan
随机推荐
智能垃圾桶(四)——树莓派pico实现超声波测距(HC-SR04)
How do I open an account now? Is there a faster and safer opening channel
Numpy's ndarray array Foundation
杰理之关于 TWS 交叉配对的配置【篇】
力扣每日一题-第31天-13.三角形的最大周长
Is the table queried by this EMR sparksql node ODPs?
LM07丨细聊期货横截面策略
bison使用error死循环的记录
win11网页版
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
Oracle expands distributed cloud services to bring comprehensive public cloud services to more customers
【VTK】MFC基于VTK8.2的网格编辑器
2022年资料员-岗位技能(资料员)操作证考试题库及模拟考试
力扣每日一题-第31天-1779.找到最近的有相同x或y坐标的点
[pbootcms模板]作文网站/文档下载网站源码
seekg ()[通俗易懂]
Pro test! Centos7 deploy PHP + spool
杰理之关于开机发起回连对耳的位置:【篇】
申请uniapp离线打包时的AppKey
又拍云 Redis 的改进之路