2016-08-30 14:44



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
betbingo 1
betbingo 2
bestbingo 2
bestbingo 1
bet365 1

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

Betbingo 4
bestbingo 3
bet365 1

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongxia2030 dongxia2030 5年前

    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.

    点赞 评论 复制链接分享
  • duanli0453 duanli0453 5年前

    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 ;

    点赞 评论 复制链接分享