当前位置:网站首页>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,
边栏推荐
- Go 字符串比较
- Subscript operator of map
- Fill the pit for repvgg? In fact, it is the repoptimizer open source of repvgg2
- 【CTF】bjdctf_2020_babyrop
- 【CTF】bjdctf_ 2020_ babyrop
- AI: the Elephant in Room
- 给RepVGG填坑?其实是RepVGG2的RepOptimizer开源
- Qiming Xingchen Huadian big data quantum security innovation laboratory was unveiled and two black technology products were released
- 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
- On shore experience of Chang'an University majoring in transportation in 2023
猜你喜欢
![[MRCTF2020]Ez_ bypass](/img/cd/bd6fe5dfc3f1942a9959a9dab9e7e0.png)
[MRCTF2020]Ez_ bypass

sql根据比较日期新建字段

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

Servlet-02 lifecycle

2022 Gdevops全球敏捷运维峰会-广州站精华回放(附ppt下载)

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

我被提拔了,怎么和原来平级的同事相处?

给RepVGG填坑?其实是RepVGG2的RepOptimizer开源

Go语言JSON 处理

Bioinformatics | 基于相互作用神经网络的有效药物-靶标关联预测
随机推荐
Precautions for map interface
2022 Gdevops全球敏捷运维峰会-广州站精华回放(附ppt下载)
基於STM32設計的寵物投喂器
[GYCTF2020]Blacklist
【CTF】bjdctf_2020_babyrop
给RepVGG填坑?其实是RepVGG2的RepOptimizer开源
高性能算力中心 — InfiniBand — Overview
Sun Tower Technology recruits PostgreSQL Database Engineer
[MRCTF2020]Ez_bypass
On shore experience of Chang'an University majoring in transportation in 2023
I have been promoted. How can I get along with my former colleagues at the same level?
Neither rain nor sunshine
Typora set up image upload service
[GXYCTF2019]BabySQli
Subscript operator of map
汇编语言中断及外部设备操作篇--06
regular expression
Mysql database introduction summary
2022高考季征文获奖名单公布
Build a security video monitoring platform using Huawei cloud ECS server