douhuan4699 2016-09-28 16:17 采纳率: 100%
浏览 53
已采纳

LEFT JOIN MySQL和PHP

I want to get some statitics out for my adminpanel. I have two tables named users and cms_prosjekt. I want to count how many projects that have the same attribute as users.

Each user have a motto that is connected to a project. For example: Motto is spirit and the project code is spirit. It won't return anything. I have two users with the same motto as code in a project.

 <?php 

   $result = mysql_query("SELECT
      users.id,

      COUNT(users.motto) AS count
    FROM
      users
      LEFT JOIN cms_prosjekt ON
        users.motto=cms_prosjekt.code
    GROUP BY
      users.motto");
 $num_rows = mysql_num_rows($result);

  echo "$num_rows";

  ?>
  • 写回答

3条回答 默认 最新

  • dongqing314511 2016-09-28 16:34
    关注

    The query should be count(*) and group by user.motto

     "SELECT
        user.motto
      , COUNT( * ) AS count
     FROM  users
     LEFT JOIN cms_prosjekt ON  users.motto=cms_prosjekt.code
     GROUP BY  users.motto"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题