unpivot

How to convert SQL Unpivot query to HANA SQL?

匆匆过客 提交于 2021-02-15 07:43:43
问题 How to convert following SQL Server query which uses unpivot to a HANA SQL query. SELECT p.CardName, REPLACE(p.groupcode1, 'QryGroup', '') groupcode1, ocqg.GroupName FROM ocrd UNPIVOT (value FOR groupcode1 IN ([QryGroup1], [QryGroup2], [QryGroup3], [QryGroup4], [QryGroup5], [QryGroup6], [QryGroup7], [QryGroup8], [QryGroup9], [QryGroup10], [QryGroup11], [QryGroup12], [QryGroup13], [QryGroup14], [QryGroup15],[QryGroup16], [QryGroup17], [QryGroup18], [QryGroup19],[QryGroup20], [QryGroup21],

How to UnPivot COLUMNS into ROWS in AWS Glue / Py Spark script

心已入冬 提交于 2021-02-11 15:05:00
问题 I have a large nested json document for each year (say 2018, 2017), which has aggregated data by each month (Jan-Dec) and each day (1-31). { "2018" : { "Jan": { "1": { "u": 1, "n": 2 } "2": { "u": 4, "n": 7 } }, "Feb": { "1": { "u": 3, "n": 2 }, "4": { "u": 4, "n": 5 } } } } I have used AWS Glue Relationalize.apply function to convert above hierarchal data into flat structure: dfc = Relationalize.apply(frame = datasource0, staging_path = my_temp_bucket, name = my_ref_relationalize_table,

Mysql merge count multiple column

て烟熏妆下的殇ゞ 提交于 2021-01-27 19:55:47
问题 I have a table(tb_data) which like this +---------+---------------------+---------------------+---------------------+---------------------+ | Disease | Additional_Disease1 | Additional_Disease2 | Additional_Disease3 | Additional_Disease4 | +---------+---------------------+---------------------+---------------------+---------------------+ | A01 | A03 | A03 | | | | A03 | A02 | | | | | A03 | A05 | | | | | A03 | A05 | | | | | A02 | A05 | A01 | A03 | | +---------+---------------------+------------

Write a SQL query to convert table from A to B

百般思念 提交于 2020-07-10 10:26:47
问题 I have a database table (table A) looks like this, in SQL Server 2016: Table A: ID Group 2018 2019 2020 ----------------------------------------- ID1 Group A 200 300 400 ID2 Group B 100 800 --- ID2 Group B ---- 500 300 I want to write a SQL query or something like that or a reporting tool to generate a report/table (convert table A to table B) as below: Table B: ID Group - Year - Value ---------------------------------------- ID1 Group A 2018 200 ID1 Group A 2019 300 ID1 Group A 2020 400 ID2

Unpivot in Google Sheets - multipe header columns and rows

試著忘記壹切 提交于 2020-05-26 08:41:12
问题 I have a summary table with about 20 columns and up to a hundred of rows, however I would like to convert it into a flat list so I can import to a database. This solution is not working properly in my case and my knowledge of JS is far beneath the ability to adjust it properly. There're three tabs in the Example sheet: Source Data - dummy data of what I currently have Desired Result - what I want to convert Source Data to What I Get - result I get when using the solution mentioned above Sheet

Converting single row into multiple rows based on values in columns

二次信任 提交于 2020-04-16 04:05:19
问题 I have a table where each record represents a person and there are many columns used to indicate what events they attended: CREATE TABLE EventAttendees ( Person VARCHAR(100), [Event A] VARCHAR(1), [Event B] VARCHAR(1), [Event C] VARCHAR(1) ) INSERT INTO EventAttendees SELECT 'John Smith','x',NULL,NULL UNION SELECT 'Jane Doe',NULL,'x','x' UNION SELECT 'Phil White','x',NULL,'x' UNION SELECT 'Sarah Jenkins','x','x','x' Which looks like this for example: SELECT * FROM Event Attendees /-----------

Converting single row into multiple rows based on values in columns

旧时模样 提交于 2020-04-16 04:05:01
问题 I have a table where each record represents a person and there are many columns used to indicate what events they attended: CREATE TABLE EventAttendees ( Person VARCHAR(100), [Event A] VARCHAR(1), [Event B] VARCHAR(1), [Event C] VARCHAR(1) ) INSERT INTO EventAttendees SELECT 'John Smith','x',NULL,NULL UNION SELECT 'Jane Doe',NULL,'x','x' UNION SELECT 'Phil White','x',NULL,'x' UNION SELECT 'Sarah Jenkins','x','x','x' Which looks like this for example: SELECT * FROM Event Attendees /-----------

Converting single row into multiple rows based on values in columns

自古美人都是妖i 提交于 2020-04-16 04:04:58
问题 I have a table where each record represents a person and there are many columns used to indicate what events they attended: CREATE TABLE EventAttendees ( Person VARCHAR(100), [Event A] VARCHAR(1), [Event B] VARCHAR(1), [Event C] VARCHAR(1) ) INSERT INTO EventAttendees SELECT 'John Smith','x',NULL,NULL UNION SELECT 'Jane Doe',NULL,'x','x' UNION SELECT 'Phil White','x',NULL,'x' UNION SELECT 'Sarah Jenkins','x','x','x' Which looks like this for example: SELECT * FROM Event Attendees /-----------