• <tfoot id='QZx4Q'></tfoot>
      <bdo id='QZx4Q'></bdo><ul id='QZx4Q'></ul>

      <legend id='QZx4Q'><style id='QZx4Q'><dir id='QZx4Q'><q id='QZx4Q'></q></dir></style></legend>
      <i id='QZx4Q'><tr id='QZx4Q'><dt id='QZx4Q'><q id='QZx4Q'><span id='QZx4Q'><b id='QZx4Q'><form id='QZx4Q'><ins id='QZx4Q'></ins><ul id='QZx4Q'></ul><sub id='QZx4Q'></sub></form><legend id='QZx4Q'></legend><bdo id='QZx4Q'><pre id='QZx4Q'><center id='QZx4Q'></center></pre></bdo></b><th id='QZx4Q'></th></span></q></dt></tr></i><div id='QZx4Q'><tfoot id='QZx4Q'></tfoot><dl id='QZx4Q'><fieldset id='QZx4Q'></fieldset></dl></div>

    1. <small id='QZx4Q'></small><noframes id='QZx4Q'>

      1. 左外连接不会从我的左表中返回所有行?

        时间:2023-08-20
          <tfoot id='1CqI6'></tfoot>
            <bdo id='1CqI6'></bdo><ul id='1CqI6'></ul>
          • <legend id='1CqI6'><style id='1CqI6'><dir id='1CqI6'><q id='1CqI6'></q></dir></style></legend>

                <i id='1CqI6'><tr id='1CqI6'><dt id='1CqI6'><q id='1CqI6'><span id='1CqI6'><b id='1CqI6'><form id='1CqI6'><ins id='1CqI6'></ins><ul id='1CqI6'></ul><sub id='1CqI6'></sub></form><legend id='1CqI6'></legend><bdo id='1CqI6'><pre id='1CqI6'><center id='1CqI6'></center></pre></bdo></b><th id='1CqI6'></th></span></q></dt></tr></i><div id='1CqI6'><tfoot id='1CqI6'></tfoot><dl id='1CqI6'><fieldset id='1CqI6'></fieldset></dl></div>
                  <tbody id='1CqI6'></tbody>

                <small id='1CqI6'></small><noframes id='1CqI6'>

                  本文介绍了左外连接不会从我的左表中返回所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用以下查询获取每天打开的页面数.

                  I am trying to get the number of page opens on a per day basis using the following query.

                  SELECT day.days, COUNT(*) as opens 
                  FROM day 
                  LEFT OUTER JOIN tracking ON day.days = DAY(FROM_UNIXTIME(open_date)) 
                  WHERE tracking.open_id = 10 
                  GROUP BY day.days
                  

                  我得到的输出是这样的:

                  The output I get it is this:

                  days opens
                  1   9
                  9   2
                  

                  问题是,在我的日期表中,我有一列包含数字 1 到 30 来表示一个月中的天数.我做了一个左外连接,我期待在天数列中显示所有天数!

                  The thing is, in my day table, I have a single column that contains the number 1 to 30 to represent the days in a month. I did a left outer join and I am expecting to have all days show on the days column!

                  但我的查询正在这样做,为什么会这样?

                  But my query is doing that, why might that be?

                  推荐答案

                  Nanne 的回答 解释了为什么你没有得到想要的结果(你的 WHERE 子句删除了行),但没有说明如何修复它.

                  Nanne's answer given explains why you don't get the desired result (your WHERE clause removes rows), but not how to fix it.

                  解决方案是将 WHERE 改为 AND 使条件成为连接条件的一部分,而不是连接后应用的过滤器:

                  The solution is to change WHERE to AND so that the condition is part of the join condition, not a filter applied after the join:

                  SELECT day.days, COUNT(*) as opens 
                  FROM day 
                  LEFT OUTER JOIN tracking
                  ON day.days = DAY(FROM_UNIXTIME(open_date)) 
                  AND tracking.open_id = 10 
                  GROUP BY day.days
                  

                  现在左表中的所有行都将出现在结果中.

                  Now all rows in the left table will be present in the result.

                  这篇关于左外连接不会从我的左表中返回所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 UPDATE 查询中执行三个表 JOIN? 下一篇:带有动态列的 MySQL 数据透视表查询

                  相关文章

                  最新文章

                  1. <i id='0b1Ln'><tr id='0b1Ln'><dt id='0b1Ln'><q id='0b1Ln'><span id='0b1Ln'><b id='0b1Ln'><form id='0b1Ln'><ins id='0b1Ln'></ins><ul id='0b1Ln'></ul><sub id='0b1Ln'></sub></form><legend id='0b1Ln'></legend><bdo id='0b1Ln'><pre id='0b1Ln'><center id='0b1Ln'></center></pre></bdo></b><th id='0b1Ln'></th></span></q></dt></tr></i><div id='0b1Ln'><tfoot id='0b1Ln'></tfoot><dl id='0b1Ln'><fieldset id='0b1Ln'></fieldset></dl></div>

                    <tfoot id='0b1Ln'></tfoot>

                    <legend id='0b1Ln'><style id='0b1Ln'><dir id='0b1Ln'><q id='0b1Ln'></q></dir></style></legend>
                    • <bdo id='0b1Ln'></bdo><ul id='0b1Ln'></ul>

                    <small id='0b1Ln'></small><noframes id='0b1Ln'>