mysql - 具有相同变量的行数

标签 mysql

我有两个表(为了更简单的示例)

第一个表包含有关每个访问者的信息(重定向)

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

相关文章:

mysql - 'num_of_cmt' 是 4 而不是 2。为什么?

mysql - SQL 连接查询以返回总和和最近的条目

mysql - 结合2个Mysql更新语句(相同列,不同值,不同条件)

mysql - 在日期时间mysql中转换一年中的 float 日期

mysql - 在 MySQL 中显示 VIEW 的内容

mysql - 如何使用 JQChart 在 CodeIgniter 中添加图形

javascript - jQuery $.get() 不运行 php 脚本

sql - 从 excel : ODBC driver does not support the requested properties 连接到 mysql

mysql - 从一个表连接到另一个表中选择最近的结果

mysql - 如何在 SQL where 子句中使用 if 条件应用用户过滤器?