当前位置:网站首页>SQL教程之SQL 中数据透视表的不同方法
SQL教程之SQL 中数据透视表的不同方法
2022-06-23 09:52:00 【知识大胖】
数据专业人员经常查看事务数据,并需要数据透视表进行进一步分析。例如,银行专家可能需要审查每笔交易以确定某些账户如何结算,或者销售分析师可能需要审查个别交易以确定某些产品的销售情况。
作为数据操作的基本技能,数据透视表通常是更广泛分析的第一步。因为它是如此基础,主要的工作表应用程序提供了创建数据透视表的函数,但它们依赖于完整的数据集。
在许多大数据应用程序中,分析工作表中的数百万行是不可行的。虽然尝试通过您最喜欢的编程语言及其库来处理这些数据可能会起作用,但从一开始就不要查询这么多数据会更有效率。相反,可以在 SQL 的查询级别上创建数据透视表。
数据
为了演示如何创建数据透视表,将生成一个显示事务数据的简单数据集。
CREATE TABLE transactions(
id INTEGER PRIMARY KEY,
client_id INTEGER,
value INTEGER
);
在这种情况下,事务表包含三个字段:每个事务的唯一 ID、与事务关联的客户端的客户端 ID 以及事务的值。

为简洁起见,仅生成了五行随机数据,但实际生产数据库可以轻松托管数十万行甚至数百万行的事务记录。
查询应该能够返回每个客户端 ID 的事务总值,而不是提取整个数据集。
#枢轴功能
PIVOT 函数是迄今为止创建数据透视表最直接的方法。从字面上看,它是作为数据透视表的实用程序设计的,其语法易于理解。
SELECT column AS column_alias,
边栏推荐
- UEFI source code learning 3.7 - norflashdxe
- Three methods to find the limit of univariate function -- lobida's rule and Taylor's formula
- mysql中innodb下的redo log什么时候开始执行check point落盘的?
- 高性能算力中心 — NVMe/NVMe-oF — NVMe-oF Overview
- Simple understanding of quick sort
- After the uncommitted transactions in the redo log buffer of MySQL InnoDB are persisted to the redo log, what happens if the transaction rollback occurs? How does the redo log handle this transaction
- J. Med. Chem. | Release: a new drug design model for deep learning based on target structure
- Unity技术手册 - 生命周期内速度限制(Limit Velocity Over Lifetime)子模块和速度继承(Inherit Velocity)子模块
- 135137138445 unable to remotely connect to the database due to disabling
- After installing these five plug-ins, pycharm can be used for takeoff!
猜你喜欢

J. Med. Chem. | Release: a new drug design model for deep learning based on target structure

RPC kernel details you must know (worth collecting)!!!

Jog sport mode

laravel8 beanstalk 使用说明

什么是BFC?BFC可以解决什么问题

Correspondence between three-tier architecture and SSM

Qiming Xingchen Huadian big data quantum security innovation laboratory was unveiled and two black technology products were released

16. system startup process

Shengshihaotong enables high-quality development with industrial Digitalization

Set the CPU to have 16 address lines and 8 data lines, and use mreq as the access control line number Connection between memory and CPU
随机推荐
[CISCN2019 华北赛区 Day2 Web1]Hack World
我被提拔了,怎么和原来平级的同事相处?
What is BFC? What problems can BFC solve
After installing these five plug-ins, pycharm can be used for takeoff!
NiO example
有没有人,计划开源一套工业级“秒杀”系统架构?
Chain implementation of stack -- linear structure
sql根据比较日期新建字段
laravel8 beanstalk 使用说明
A 32KB cache with direct mapping Memory exercises after class
薄膜干涉数据处理
Web -- Information Disclosure
正则表达式
mysql innodb 的 redo log buffer 中未 commit 的事务持久化到 redo log 后,万一事务 rollback 了怎么办?redo log 怎么处理这个事务操作?
Getting started with cookies and sessions
ThinkPHP 2. X/3.0 vulnerability recurrence
Lu Qi invests in quantum computing for the first time
RGB and CMYK color modes
High performance computing center RDMA implementation technology
漫画 | Code Review快把我逼疯了!