dta25920 2014-12-19 09:26
浏览 32
已采纳

在mySQL中计算值

I have a mySql database and I have a question about counting several values with the same "Provider_id". Let me explain it as simple as possible. I have 3 rows: Provider_id (No unique values at end of text), click_count(How many clicks on their site, int value) and logo_id(This one is the same as Provider_id so they could be connected). "Provider_id" and "click_count" are in the same table and logo_id is from a different table. I want to match "Provider_id" and "Logo_id" and want to count click_count with the matching Provider_id.

For example:

(table 1)

Provider_id = 102 click_count = 10

Provider_id = 102 click_count = 22

(table 2)

logo_id = 102

-- What I want to get --

Provider_id = 102 click_count = 32

Could anyone help me with this?

Explained Provider_id:

There are unique website id's in the table with Provider_id so the Provider_id doens't have to be unique.

  • 写回答

3条回答 默认 最新

  • doujia1988 2014-12-19 09:29
    关注

    What you can do is join both tables and do group by Provider_id and taking the sum of click_count will solve the problem.So try like this

    select t1.Provider_id,sum(t1.click_count) from table_1 as t1 
    inner join table_2 as t2 on t1.Provider_id = t2.logo_id 
    group by t1.Provider_id
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动