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,一经查实,立即删除!

相关文章

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

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

Genome-wide association studies in R

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

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

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

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

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

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

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

Unity 命令模式(实例详解)

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

C语言-算法-背包

[USACO07DEC] Charm Bracelet S(01背包) 题目描述 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…

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

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

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

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

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

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

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

当我们遇到网页加载缓慢时&#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…

短视频批量抽帧怎么做

随着短视频的流行&#xff0c;越来越多的创作者需要处理大量的视频素材。其中&#xff0c;批量抽帧是一项常见的需求&#xff0c;它可以帮助我们快速提取视频中的关键帧&#xff0c;以便进行后续的处理或分析。那么&#xff0c;如何高效地进行短视频批量抽帧呢&#xff1f;接下…

微信开发者工具 git 拉取 failed invalid authentication scheme

微信开发者工具 git 拉取 failed invalid authentication scheme 拉取代码时报错,无效身份认证 解决方案: 1.检查git地址是否正常 2.检查git用户名密码是否正确

什么工具能将视频转成gif?分享一个在线制作gif网站

Gif动图看起来效果非常的炫酷&#xff0c;也很复杂。这种gif动图制作起来是不是也很麻烦呢&#xff1f;其实制作gif动画的方法非常的简单&#xff0c;不用下载软件&#xff0c;小白也能操作。只需要使用在线制作gif&#xff08;https://www.gif.cn/&#xff09;工具-GIF中文网&…

代码随想录算法训练营第十六天 |104.二叉树的最大深度,111.二叉树的最小深度,222.完全二叉树的节点个数(待补充)

104.二叉树的最大深度 1、题目链接&#xff1a;力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚爱的技术成长平台 2、文章讲解&#xff1a;代码随想录 3、题目&#xff1a; 给定一个二叉树&#xff0c;找出其最大深度。 二叉树的深度为根节点到最远叶子节点的最长…

《30天自制操作系统》 第一周(D1-D7) 笔记

前言&#xff1a;这是我2023年5月份做的一个小项目&#xff0c;最终是完成了整个OS。笔记的话&#xff0c;只记录了第一周。想完善&#xff0c;却扔在草稿箱里许久。最终决定&#xff0c;还是发出来存个档吧。 一、汇编语言 基础指令 MOV: move赋值&#xff0c;数据传送指令…

提升养殖场效益,从饲料粉碎机开始

为了提高养殖效益&#xff0c;养殖户可以从很多方面着手&#xff0c;其中饲料成本是一个重要的因素。为了降低饲料成本&#xff0c;养殖户可以考虑从饲料粉碎环节入手。通过购买和采用高效、低成本的饲料粉碎机&#xff0c;养殖户可以更好地控制饲料成本&#xff0c;提高饲料的…

Linux 驱动开发基础知识—— LED 驱动程序框架(四)

个人名片&#xff1a; &#x1f981;作者简介&#xff1a;一名喜欢分享和记录学习的在校大学生 &#x1f42f;个人主页&#xff1a;妄北y &#x1f427;个人QQ&#xff1a;2061314755 &#x1f43b;个人邮箱&#xff1a;2061314755qq.com &#x1f989;个人WeChat&#xff1a;V…