Dear Experts,I have a SQL select statement that outputs data as follows.----------------------------
ID     Attribute     Value
----------------------------
10    username    user1
10    password    pass1
11    username    user2
11    password    pass2
---------------------------I want to rotate this table as follows:
--------------------------------
ID     username    password
--------------------------------
10    user1          pass1
11    user2          pass2
--------------------------------How can I do this? I'm using MYSQL.

解决方案 »

  1.   

    select id,username,password from tableName limit 2;
      

  2.   

    select a.id,a.username,b.password
    from (
    select ID,Value as username
    from yourTable
    where Attribute='username') a inner join 
    (select ID,Value as password
    from yourTable
    where Attribute='password') b on a.id=b.id
    == 思想重于技巧 ==
      

  3.   

    select a.id,a.Value,b.Value from (select id,Value from TableName where Attribute="username") as a left join (select id,Value from TableName where Attribute="password") as b on a.id=b.id;