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
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 ;