当前位置:网站首页>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;
边栏推荐
- Ttchat x Zadig open source co creates helm access scenarios, and environmental governance can be done!
- What are outer chain and inner chain?
- When you are young, you should be awake to fight, and when you are young, you should have the courage to try
- 正大期货留4数据整合
- 嵌入式数据库开发编程(四)——DDL、DML
- Pro test! Centos7 deploy PHP + spool
- 杰理之关于 TWS 声道配置【篇】
- 镜像漏洞扫描工具:Trivy
- Nature | biosynthetic potential of global marine microbiome
- 将文件夹打包成iso
猜你喜欢

When a technician becomes a CEO, what "bugs" should be modified?

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

基于字节码的统一异常上报实践

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

Unified exception reporting practice based on bytecode

文件包含之日志中毒(User-Agent)

钛动科技:我们的 Zadig 落地之路

Initial use of eolink

What are outer chain and inner chain?

leetcode刷题:字符串07(重复的子字符串)
随机推荐
文件包含之日志中毒(User-Agent)
ES6 数组方法
Is the table queried by this EMR sparksql node ODPs?
合约量化交易系统玩法开发 (现成案例分析)
大家有没有觉得学机械的人很可怕?
MySQL enable slow query
Jerry's configuration of TWS cross pairing [chapter]
PyTorch学习之归一化层(BatchNorm、LayerNorm、InstanceNorm、GroupNorm)[通俗易懂]
shell判断命令是否执行成功
Equals increases execution speed / performance optimization
助力极致体验,火山引擎边缘计算最佳实践
Easy express: we use Zadig to realize 10000 times of construction and deployment, smart operation and maintenance, and release development productivity
When you are young, you should be awake to fight, and when you are young, you should have the courage to try
力扣每日一题-第31天-1779.找到最近的有相同x或y坐标的点
Imile uses Zadig's multi cloud environment to deploy thousands of times a week to continuously deliver global business across clouds and regions
Numpy's ndarray array Foundation
Installation and configuration of MariaDB
The blackened honeysnow ice city wants to grasp the hearts of consumers by marketing?
论文复现——AC-FPN:Attention-guided Context Feature Pyramid Network for Object Detection.
如何通过WinDbg获取方法参数值