![](/img/trans.png)
[英]Mysql sum a column group by id, then divide that sum for each id with value from another column in another table with the matching id for each row
[英]Group by matching from another table
我需要通过client_id
对流量列表(重定向)进行分组。
流量在一个表中( traffic_table
)client_id和不同的客户端URL在另一个表中。
我的问题是匹配需要是模糊/ LIKE,因为我没有连接选项。 每个client_id可以有多个网址。 客户端URL需要与流量表中的域列匹配,并具有某种LIKE。
我无法得到这个以显示正确的结果。
有人有想法吗?
示例数据:
Traffic_table:
domain count
www.google.com/dasdasdas 45
google.com/2lkj24j 755
http://www.google.de/42dasdsa 74
www.bing.com/1321 65
http://www.bing.de/1321ds 74
Client_table:
client_id url
1 google.com
1 google.de
2 bing.com
2 bing.de
我希望我能正确理解你的问题,在我看来你想要总结所有按客户网址分组的流量计数。 比你可以轻松加入喜欢表达:
SELECT c.url,SUM(t.count) FROM client c JOIN traffic t ON t.domain LIKE CONCAT('%',c.url,'%') GROUP BY c.client_id
您的示例数据的结果:
//编辑:SELECT c.client_id,SUM(...优于c.url
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.