Mysql搜索查询按品牌和总和品牌价值排序

Mysql搜索查询按品牌和总和品牌价值排序

问题描述:

Hi I am trying to run a query where brand_name should be distinct but the brand_value show sum. Mysql TABLE structure with Primary key

betbingo 1 www.abc.com
betbingo 1 www.abc.com
betbingo 2 www.abc.com
bestbingo 2 www.abc.com
bestbingo 1 www.abc.com
bet365 1 www.abc.com

I want brand column distinct and show sum of 2nd column. So the result should be like this

Betbingo 4 www.abc.com
bestbingo 3 www.abc.com
bet365 1 www.abc.com

I am using While loop in php
Can you please help me out.
Thanks

您好我正在尝试运行查询,其中 brand_name code>应该 distinct 但 brand_value code>显示 sum code>。 Mysql code> TABLE code>结构与主键 code> p>

betbingo 1 www.abc.com 代码>
betbingo 1 www.abc.com code>
betbingo 2 www.abc.com code>
bestbingo 2 www.abc.com code>
bestbingo 1 www.abc.com code>
bet365 1 www.abc.com code>
p>

我希望品牌列清晰,并显示第2列的总和。 所以结果应该是这样的
p>

Betbingo 4 www.abc.com code>
bestbingo 3 www.abc.com code>
bet365 1 www.abc.com code>
p>

我在php中使用While循环
你能不能请 帮帮我。谢谢 p> div>

Use group by clause. It will select distinct brand name from your table.

select brand, sum(2nd column) from your_table group by brand

Hope it will help.

Not clear about the primary key but group by and sum() in the sql should do the trick

Select brand , sum(brand_value) as sum_of_brandvalue from tablename group by brand ;