I have been tring to unpivot a table from google sheets table like the one below into (EAV) or Date, ldap, Shift:
Date Ldap1 Ldap2 Ldap3 </p>
2020-04-01 Shift A Shift B Shift C </p>
2020-04-02 Shift A Shift B Shift C</p>
2020-04-03 Shift A Shift B Shift C</p>
My initial code (arranged from somewhere else) works but I need to perform this around 400 times as columns go up to 400. Any ideas to make this faster and more practical?
SELECT date, "ldap1" AS id_name, ldap1 AS id
FROM yt_tns_vendor_ops_ham_cog_leads.workflow_test
UNION ALL
SELECT date, "ldap2" AS id_name, ldap2 AS id
FROM yt_tns_vendor_ops_ham_cog_leads.workflow_test
ORDER BY date, id_name
Result:
date id_name id
2020-04-01 Ldap1 Shift A
2020-04-01 Ldap2 Shift B
2020-04-02 Ldap1 Shift A
2020-04-02 Ldap2 Shift B
2020-04-03 Ldap1 Shift A
2020-04-03 Ldap2 Shift B
2020-04-04 Ldap1 Shift A
2020-04-04 Ldap2 Shift B
2020-04-05 Ldap1 Shift A
2020-04-05 Ldap2 Shift B
2020-04-06 Ldap1 Shift A
2020-04-06 Ldap2 Shift B
2020-04-07 Ldap1 WO
2020-04-07 Ldap2 WO
2020-04-08 Ldap1 WO
2020-04-08 Ldap2 WO
2020-04-09 Ldap1 Shift A
2020-04-09 Ldap2 Shift B
2020-04-10 Ldap1 Shift A
2020-04-10 Ldap2 Shift B
2020-04-11 Ldap1 Shift A
2020-04-11 Ldap2 Shift B
2020-04-12 Ldap1 Shift A
2020-04-12 Ldap2 Shift B
2020-04-13 Ldap1 Shift A
2020-04-13 Ldap2 Shift B
2020-04-14 Ldap1 Shift A
2020-04-14 Ldap2 Shift B
2020-04-15 Ldap1 WO
2020-04-15 Ldap2 WO
2020-04-16 Ldap1 WO
2020-04-16 Ldap2 WO
2020-04-17 Ldap1 Shift A
2020-04-17 Ldap2 Shift B
2020-04-18 Ldap1 Shift A