当前位置:网站首页>PSQL column to row

PSQL column to row

2022-06-25 02:27:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm your friend, Quan Jun .

demand

Student transcript

  • Create table initialization
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;
  • Transfer line column
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;

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151771.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242246018511.html