如何从mysql查询中检索特定格式的数据?

时间:2016-04-22 06:58:44

标签: php mysql

我有一个table = table1,此表中的数据如下

user_id    user_name  count_activity  activity_name
1            ravi         2                login    
2            rahul        5                logout
1            ravi         6                send mail 
3            vinod        10               update authrization
2            rahul        50               delete authrization

我想用这些数据制作3个这样的视图。

First View                   Second View               Third View

Activity        Details     Activity     details     Activity       details 
user             ravi       user          rahul       user           vinod
login            2          logout         5          update auth..   10
send mail        6          delete auth..  50     

2 个答案:

答案 0 :(得分:0)

要从数据库中获取数据,这是查询:

select user_name, activity_name activity, count_activity as Details from <tablename> order by user_name

您可以根据需要添加where子句以获取数据。

答案 1 :(得分:0)

select activity_name as Activity,count_activity as Details  from table where user_name ='ravi';

视图1

其他观点也是如此