对MySQL表进行解构操作
P粉549986089
2023-08-29 18:24:12
<p>我想知道是否可以将这个输出更改为:</p>
<pre class="brush:php;toolbar:false;">User Database Select Insert Update Delete Create References Alter Drop
------------- ------------------ ------ ------ ------ ------ ------ ---------- ------ --------
mysql.session performance_schema 1 0 0 0 0 0 0 0
mysql.sys sys 0 0 0 0 0 0 0 0</pre>
<p>变成这样:</p>
<pre class="brush:php;toolbar:false;">Users Privileges performance_schema sys
----- ---------- ------------------ ---
mysql.session Select 1
mysql.session Insert 0
mysql.session Update 0
mysql.session Delete 0
mysql.session Create 0
mysql.session References 0
mysql.session Alter 0
mysql.session Drop 0
mysql.sys Select 0
mysql.sys Insert 0
mysql.sys Update 0
mysql.sys Delete 0
mysql.sys Create 0
mysql.sys References 0
mysql.sys Alter 0
mysql.sys Drop 0</pre>
<p>我使用的查询语句是:</p>
<pre class="brush:php;toolbar:false;">SELECT
DISTINCT
USER "User",
db "Database",
IF(Select_priv = 'Y', '1 ', '0') AS "Select",
IF(Insert_priv = 'Y', '1 ', '0') AS "Insert",
IF(Update_priv = 'Y', '1', '0') AS "Update",
IF(Delete_priv = 'Y', '1', '0') AS "Delete",
IF(Create_priv = 'Y', '1', '0') AS "Create",
IF(References_priv = 'Y', '1', '0') AS "References",
IF(Alter_priv = 'Y', '1', '0') AS "Alter",
IF(Drop_priv = 'Y', '1', '0') AS "Drop"
FROM
mysql.db
ORDER BY
USER, Db;</pre>
<p>任何帮助将不胜感激。提前谢谢!</p>
这是一个“unpivot”的示例:
抱歉,无法自动根据查询找到的数据为每个模式定义列的透视或反透视查询。在查询开始读取数据之前,必须在查询中设置列。