我有两个表(为了更简单的示例)
第一个表包含有关每个访问者的信息(重定向)
|user_agent||unique_id|
|ua123||321|
|ua231||323|
|ua123||322|
第二个表是“销售额”
|unique_id||price|
|322||1.7|
|321||0.5|
我想知道如何构建将显示以下内容的查询:
|unique_id||price||number of row with non unique user_agent with sale|
|322||0.7||3|
|321||0.5||1|
最佳答案
试试这个:
select
s.unique_id,
s.price,
(select count(user_agent) from visitor v where v.unique_id = s.unique_id) as nbr_visit
from sales s
关于mysql - 具有相同变量的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41091162/