Rumah > Soal Jawab > teks badan
P粉4818158972023-08-30 16:00:12
Berikut ialah contoh "nyahpivot":
(SELECT User AS Users, 'Select' AS Privileges, 1 AS PrivOrder, MAX(CASE db WHEN 'performance_schema' THEN Select_priv='Y' END) AS `performance_schema`, MAX(CASE db WHEN 'sys' THEN Select_priv='Y' END) AS `sys` FROM db GROUP BY User) UNION (SELECT User, 'Insert', 2, MAX(CASE db WHEN 'performance_schema' THEN Insert_priv='Y' END), MAX(CASE db WHEN 'sys' THEN Insert_priv='Y' END) FROM db GROUP BY User) UNION (SELECT User, 'Update', 3, MAX(CASE db WHEN 'performance_schema' THEN Update_priv='Y' END), MAX(CASE db WHEN 'sys' THEN Update_priv='Y' END) FROM db GROUP BY User) UNION (SELECT User, 'Delete', 4, MAX(CASE db WHEN 'performance_schema' THEN Delete_priv='Y' END), MAX(CASE db WHEN 'sys' THEN Delete_priv='Y' END) FROM db GROUP BY User) UNION (SELECT User, 'Create', 5, MAX(CASE db WHEN 'performance_schema' THEN Create_priv='Y' END), MAX(CASE db WHEN 'sys' THEN Create_priv='Y' END) FROM db GROUP BY User) ... ORDER BY Users, PrivOrder;
Maaf, tiada cara untuk mentakrifkan pertanyaan pangsi atau nyahpaut secara automatik untuk lajur setiap skema berdasarkan data yang ditemui oleh pertanyaan. Lajur mesti ditetapkan dalam pertanyaan sebelum pertanyaan mula membaca data.