mysql - 如何进行查询

标签 mysql sql database

查看表有 store_idx、user_idx 等...

我想创建一个查询语句,获取有关用户使用输入的 user_id 值添加书签的商店的信息。

我提出的查询语句是

select A.store_name
     , A.store_img
     , count(B.store_idx) as review_cnt 
  from board.store A 
  Left 
  Join board.review B 
    On A.store_idx is B.store_idx 
 where store_idx is (select A.store_idx from bookmark where user_id = ?)

但是,没有任何结果。

帮帮我..

最佳答案

请使用以下查询:

SELECT store_name
     , store_img
     , SUM(review_cnt) AS review_cnt
  FROM
     ( SELECT DISTINCT A.store_name
            , A.store_img
           , CASE WHEN B.store_idx IS NULL THEN 0 ELSE 1 END AS review_cnt
       FROM bookmark br
       JOIN board.store A 
            ON A.store_idx = br.store_idx
       LEFT 
           JOIN board.review B 
             ON A.store_idx = B.store_idx 
    WHERE br.user_id = ?
     )T

关于mysql - 如何进行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50673496/

相关文章:

php - 如何使用 Jquery 和 PHP 将行复制到 MySQL 中的另一个表?

mysql - 我正在尝试使用具有可变 FK 的架构创建一个表(订单)

mysql - IVRS应答记录器

database - 我将如何创建 DCG 来解析有关数据库的查询?

php - 尝试使用 mysql 中的数组在 PHP 中以某种方式格式化 json

php - MySQL 按字母表选择名称分组,每个字母限制为 n 个结果

sql - 从 SQL Server 检索压缩的 GZip 信息

MySQL 查询 : Find column where key like "Y" then use another columns unique ID to update a third column with something?

database - 打开标准 Jet DB 4.0 文件 (*.vmd)

php - 匹配两个不带秒的日期并显示结果