简体   繁体   English

在一行mysql中为一个用户选择所有行

[英]select all rows for one user in one row mysql

I have a mysql table which has the below structure 我有一个具有以下结构的mysql表

id,username,attribute,value,realname,birthdate,phone 

and I have these records in the table 我在桌子上有这些记录

1,john,Cleartext-Password,ss,johnsmith,1/1/1990,9786865754
2,john,Expiration,20/1/2018,null,null,null

I want to write a query that shows the below result 我想写一个查询,显示以下结果

username|password|expir     |realname|birthdate|phone 
john    |ss      |20/1/2018 |johnsmith|1/1/1990|9786865754

I tried using the query mentioned below. 我尝试使用下面提到的查询。 But I don't seem to get the desired result. 但是我似乎没有得到理想的结果。

select c1.username ,c1.value as 'password',c1.adsoyad,c1.telefon,c1.email,c1.dtarih,c1.tcno,c2.value as 'expired' from radcheck c1 INNER join radcheck c2 on c1.username=c2.username and c1.attribute='Cleartext-Password' and c2.attribute='Expiration' and c1.username='john' and c2.username='john'

Does conditional aggregation do what you want? 条件聚合是否可以满足您的需求?

select c.username,
       max(case when c.attribute = 'password' then c.value end) as password,
       max(case when c.attribute = 'expiration' then c.value end) as expiration,
       max(c.realname) as realname, min(c.birthdate) as birthdate, max(c.phone) as phone
from radcheck c
group by username

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM