Oracle分栏(非分页)查询

  不知道Oracle怎么进行数据分栏(分栏: 因数据列过长, 部分数据作为新列显示). 在这里先记录一下粗浅的查询方法.
数据源例子:

    select '日用百货' as cat, '手电筒' as name, 20 as amount, '2024-01-27' as dt from dualunion allselect '餐饮美食' as cat, '鸡公煲' as name, 15.9 as amount, '2024-01-27' as dt from dualunion allselect '餐饮美食' as cat, '海带粉' as name, 6 as amount, '2024-01-27' as dt from dualunion allselect '日用百货' as cat, '垃圾桶' as name, 9.9 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '大铁锅' as name, 66 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '电火锅' as name, 216 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '电饭锅' as name, 166 as amount, '2024-01-26' as dt from dualunion allselect '餐饮美食' as cat, '老乡鸡' as name, 19.9 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '塑料小板凳' as name, 8 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '垃圾袋' as name, 7.5 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '塑料靠背凳' as name, 10 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '鞋刷' as name, 4 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '撑衣杆' as name, 8.5 as amount, '2024-01-26' as dt from dualunion allselect '餐饮美食' as cat, '海带粉' as name, 6 as amount, '2024-01-26' as dt from dual

  思路: 创造提取新列的条件, 然后进行关联查询

with t as (select '日用百货' as cat, '手电筒' as name, 20 as amount, '2024-01-27' as dt from dualunion allselect '餐饮美食' as cat, '鸡公煲' as name, 15.9 as amount, '2024-01-27' as dt from dualunion allselect '餐饮美食' as cat, '海带粉' as name, 6 as amount, '2024-01-27' as dt from dualunion allselect '日用百货' as cat, '垃圾桶' as name, 9.9 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '大铁锅' as name, 66 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '电火锅' as name, 216 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '电饭锅' as name, 166 as amount, '2024-01-26' as dt from dualunion allselect '餐饮美食' as cat, '老乡鸡' as name, 19.9 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '塑料小板凳' as name, 8 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '垃圾袋' as name, 7.5 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '塑料靠背凳' as name, 10 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '鞋刷' as name, 4 as amount, '2024-01-26' as dt from dualunion allselect '日用百货' as cat, '撑衣杆' as name, 8.5 as amount, '2024-01-26' as dt from dualunion allselect '餐饮美食' as cat, '海带粉' as name, 6 as amount, '2024-01-26' as dt from dual
)
, tmd as (select p.*, ceil(p.rn/3) as dv, mod(p.rn, 3) as mdfrom (select row_number() over (partition by cat order by dt,amount desc) as rn, t.*from t) p
)
select t1.cat, t1.name as name1,t1.amount as amount1, t2.name as name2,t2.amount as amount2, t3.name as name3,t3.amount as amount3
from (select * from tmd where md=1) t1
left join (select * from tmd where md=2) t2 on t1.cat=t2.cat and t1.dv=t2.dv
left join (select * from tmd where md=0) t3 on t1.cat=t3.cat and t1.dv=t3.dv
order by t1.cat,t1.dv,t1.md
;

  查询结果:

CATNAME1AMOUNT1NAME2AMOUNT2NAME3AMOUNT3
日用百货电火锅216电饭锅166大铁锅66
日用百货塑料靠背凳10垃圾桶9.9撑衣杆8.5
日用百货塑料小板凳8垃圾袋7.5鞋刷4
日用百货手电筒20NULLNULLNULLNULL
餐饮美食老乡鸡19.9海带粉6鸡公煲15.9
餐饮美食海带粉6NULLNULLNULLNULL

在这里插入图片描述
后面再找时间研究吧. (2024-01-27)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/650589.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

QT 中如何使用 JSON 功能?

在 Qt 中,您可以使用 QJsonDocument、QJsonObject 和 QJsonArray 类来处理 JSON 数据。以下是一个简单的示例,说明如何在 Qt 中使用这些类来解析和生成 JSON 数据: 1. 包含必要的头文件 首先,确保您的项目中包含了必要的 Qt JSO…

SSEBop FEWS V6蒸散发ET年和月尺度数据分享

一、数据简介 SSEBOP FEWS V6是一个用于估算蒸散发(evapotranspiration)的模型或数据集。蒸散发是指地表和植物蒸发以及植物蒸腾的总和,是水循环中重要的组成部分。 SSEBOP FEWS V6是由美国地质调查局(USGS)开发的一…

C# LING查询语法学习,扩展方法的使用

class Program { #region 示例1&#xff1a;不使用LINQ查询数组 //static void Main(string[] args) //{ // int[] nums { 1, 7, 2, 6, 5, 4, 9, 13, 20 }; // List<int> list new List<int>(); // foreach (int item in nums) …

Genome-wide association studies in R

全基因组关联&#xff08;GWA&#xff09;研究扫描整个物种基因组&#xff0c;寻找多达数百万个SNPs与特定感兴趣特征之间的关联。值得注意的是&#xff0c;感兴趣的性状实际上可以是归因于群体的任何类型的表型&#xff0c;无论是定性的&#xff08;例如疾病状态&#xff09;还…

支持IPv4与IPv6双协议栈的串口服务器,IPv6串口服务器

物联网是啥玩意儿&#xff1f;这是首先要搞明白的。按照百度百科的说法&#xff0c;是将各种信息传感设备&#xff0c;如射频识别&#xff08;RFID&#xff09;装置、红外感应器、全球定位系统、激光扫描器等种种装置与互联网结合起来而形成的一个巨大网络。这个说法有些复杂&a…

Java入门高频考查基础知识7-深入挖掘Java集合框架的奇幻世界2(39题2.8万字参考答案)

Java 集合是 Java 编程中至关重要的组成部分&#xff0c;它为开发者提供了丰富、灵活、高效的数据结构和算法。无论是初学者还是有经验的开发者&#xff0c;在使用 Java 进行编程时都会频繁地接触到集合框架。这篇文章将深入探讨 Java 集合的重要性&#xff0c;以及为什么它对于…

简单记录一下如何安装python以及pycharm(图文教程)(可供福建专升本理工类同学使用)

本教程主要给不懂计算机的或者刚刚开始学习python的同学&#xff08;福建专升本理工类&#xff09;&网友学习使用&#xff0c;基础操作&#xff0c;比较详细&#xff0c;其他问题等待补充&#xff01; 安装Python 1.进入python官网&#xff08;https://www.python.org/&a…

【Vue】1-3、Webpack 中的 loader

一、概述 在实际开发过程中&#xff0c;webpack 默认只能打包处理以 .js 后缀结尾的模块。 其他的非 .js 后缀名结尾的模块 webpack 默认处理不了&#xff0c;需要调用 loader 加载器才可以正常打包&#xff0c;否则会报错&#xff01; loader 加载器的作用&#xff1a;协助…

Unity 命令模式(实例详解)

文章目录 示例1&#xff1a;基础命令类结构示例2&#xff1a;旋转对象命令示例3&#xff1a;增加道具命令示例4&#xff1a;切换场景命令示例5&#xff1a;播放音效命令 在Unity中使用命令模式&#xff08;Command Pattern&#xff09;是一种常见的设计模式&#xff0c;用于实现…

在Python中的集合是什么

目录 创建集合 集合的特性 集合的基本操作 集合的运算 集合的遍历和判断元素是否存在 总结 在Python中&#xff0c;集合&#xff08;Set&#xff09;是一个内置的数据类型&#xff0c;用于存储不重复的元素集合。集合的特点是元素是无序的&#xff0c;且每个元素是唯一的…

C语言-算法-背包

[USACO07DEC] Charm Bracelet S&#xff08;01背包&#xff09; 题目描述 Bessie has gone to the mall’s jewelry store and spies a charm bracelet. Of course, she’d like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. E…

apt-mark详解

文章目录 1、简介2、apt-mark auto packagename3、apt-mark manual4、apt-mark hold5、apt-mark unhold6、apt-mark showauto7、apt-mark showmanual8、apt-mark showhold 1、简介 apt-mark常用于标记一个包是否是自动安装的。 2、apt-mark auto packagename 标记一个包为自…

ssh异常报错:Did not receive identification string from

一、问题描述 某次外出在异地工作场所xshell炼乳远程服务器时&#xff0c;报错&#xff1a;Connection closed by foreign host. D&#xff0c;服务器查看secure日志或sshd服务状态会显示&#xff1a;id not receive identification string from client_ip; 二、分析处理 1&a…

多表查询,

1&#xff0c;多表查询 实际开发中&#xff0c;一个项目通常需要很多张表才能完成。例如:一个商城项目就需要分类表(category)、商品表(products)、订单表(orders)等多张表。且这些表的数据之间存在一定的关系&#xff0c;接下来我们将在单表的基础上&#xff0c;一起学习多表…

如何在前端项目里接入Sentry监控系统并通过企业微信通知

能不能让用户录个屏过来呀&#xff1f; 用户使用的是什么机型的手机&#xff1f; 用户使用的什么浏览器呀&#xff1f; 用户的网络是什么情况&#xff1f; … … 线上出现问题时&#xff0c;技术部和业务部同学之间的对话诸如此类…业务同学也很栓Q呀&#xff0c;硬着头皮去问客…

element-UI上传文件后valid提示不消失

问题描述&#xff1a;上传文件完成后&#xff0c;必填信息提示不消失 解决方法&#xff1a;在<el-form-item>标签添加show-message属性&#xff0c;字段为空时才显示提示信息 <el-form-item :prop"fileList" :show-message"!form.fileList || !form.f…

OPEN NT 4.5 编译方法和源代码下载

OPEN NT 4.5&#xff08;源代码编译方法&#xff09; 编译Windows NT 4.0到操作系统的详细方法 OPEN 4.5 ​​​​​​下载 &#xff1a;https://download.csdn.net/download/MYMOTOE6/88786570 ISO https://download.csdn.net/download/MYMOTOE6/88786572 OPEN NT 4.5&#…

LeetCode:1701. 平均等待时间(Java 模拟)

目录 1701. 平均等待时间 题目描述&#xff1a; 实现代码与解析&#xff1a; 简单模拟 原理思路&#xff1a; 1701. 平均等待时间 题目描述&#xff1a; 有一个餐厅&#xff0c;只有一位厨师。你有一个顾客数组 customers &#xff0c;其中 customers[i] [arrivali, time…

为什么网页打开慢?是服务器的问题吗?

当我们遇到网页加载缓慢时&#xff0c;首先想到的可能是服务器的问题。的确&#xff0c;服务器是影响网页加载速度的一个重要因素。然而&#xff0c;这并非是唯一的原因。实际上&#xff0c;网页加载速度受多种因素影响&#xff0c;包括但不限于服务器、网络带宽、DNS解析时间、…

c# cad2016选择封闭多段线获取多段线面积

在C#中&#xff0c;如果你想要通过AutoCAD .NET API来选择封闭多段线内部的其他闭合多段线并计算它们各自的面积&#xff0c;可以遵循以下基本步骤&#xff1a; 1、加载AutoCAD库&#xff1a; 确保你的C#项目引用了Autodesk.AutoCAD.Interop和Autodesk.AutoCAD.Interop.Common…