开发者

MySQL results by userd_id?

开发者 https://www.devze.com 2023-03-12 11:14 出处:网络
I have the following MySQL database table structure: name| product| client_id JOHN BROWN | test1.com| 122

I have the following MySQL database table structure:

name        | product         | client_id 
JOHN BROWN | test1.com     | 122 
JANE SMITH  | hosting1     | 122 
DAN JOHNSON | 开发者_StackOverflowtest2.com | 355

How to show mysql query results in php in order to get tables with results grouped by client_id. The main point is I need those details emailed by client_id, so in the current example I should get two separated tables fore those two clients.


Assuming your table is called signups

SELECT client_id, 
GROUP_CONCAT(DISTINCT name_product_email
ORDER BY name_product_email DESC SEPARATOR ',')
FROM (
    SELECT CONCAT(name, ' has this product: ', product) as name_product_email, client_id FROM signups)
GROUP BY client_id;


select client_id, group_concat(product)
from my_table
group by 1;

will produce output like:

122, "test1.com,hosting1"
355, "test2.com"

etc

0

精彩评论

暂无评论...
验证码 换一张
取 消