当前位置:网站首页>psql 列转行
psql 列转行
2022-06-24 22:47:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
需求
学生成绩表
- 创建表初始化
CREATE TABLE public.test ( name VARCHAR(20), score FLOAT, total_availability FLOAT, shelf_availability FLOAT );
INSERT INTO public.test (name, score, total_availability, shelf_availability) VALUES ('A', 1, 1.1, 1.2);
INSERT INTO public.test (name, score, total_availability, shelf_availability) VALUES ('B', 3, 2.1, 2.2);
INSERT INTO public.test (name, score, total_availability, shelf_availability) VALUES ('C', 6, 3.3, 3.4);
INSERT INTO public.test (name, score, total_availability, shelf_availability) VALUES ('D', 10, 4.1, 4.2);
SELECT * FROM public.test;
- 行转列
SELECT name, score, unnest(ARRAY ['total_availability' :: TEXT, 'shelf_availability' :: TEXT]) AS kpi_details, unnest( ARRAY [public.test.total_availability :: NUMERIC(30, 16), public.test.shelf_availability :: NUMERIC(30, 16)]) AS value FROM public.test;
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151771.html原文链接:https://javaforall.cn
边栏推荐
- 02-Epicor二次开发常用代码
- 困牛排序(寒假每日一题 40)
- When an interface has an exception, how do you analyze the exception?
- 当一个接口出现异常时候,你是如何分析异常的?
- 入坑机器学习:一,绪论
- Fatigue liée à l'examen du marché secondaire des médicaments innovants: succès clinique de la phase III et approbation du produit
- 数据库系统概论必背知识
- TSDB在民机行业中的应用
- 【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献
- Application of TSDB in civil aircraft industry
猜你喜欢
Software testing salary in first tier cities - are you dragging your feet
DDD concept is complex and difficult to understand. How to design code implementation model in practice?
左手梦想 右手责任 广汽本田不光关注销量 还有儿童安全
How to quickly familiarize yourself with the code when you join a new company?
进入阿里做测试员遥不可及?这里或许有你想要的答案
【FPGA】串口以命令控制温度采集
Dataease template market officially released
When they are in private, they have a sense of propriety
Sumati GameFi生态纵览,神奇世界中的元素设计
Redis
随机推荐
Application of TSDB in civil aircraft industry
左手梦想 右手责任 广汽本田不光关注销量 还有儿童安全
Sumati gamefi ecological overview, element design in the magical world
Qt中使用QDomDocument操作XML文件
疫情防控,居家办公,网上授课之心得 | 社区征文
TSDB在民机行业中的应用
2022-06-24:golang选择题,以下golang代码输出什么?A:1;B:3;C:4;D:编译失败。 package main import ( “f
Of the seven levels of software testers, it is said that only 1% can achieve level 7
Taishan Office Technology Lecture: a simple study of Chinese punctuation in vertical arrangement
How to get the picture outside the chain - Netease photo album [easy to understand]
jwt
Build and train your own dataset for pig face recognition
Is it out of reach to enter Ali as a tester? Here may be the answer you want
入职一家新公司,如何快速熟悉代码?
华为、阿里等大厂程序员真的好找对象吗?
02 common codes for Epicor secondary development
入坑机器学习:一,绪论
困牛排序(寒假每日一题 40)
一线城市软件测试工资——你拖后腿了吗
File system - basic knowledge of disk and detailed introduction to FAT32 file system