<legend id='kjFMs'><style id='kjFMs'><dir id='kjFMs'><q id='kjFMs'></q></dir></style></legend>

    <small id='kjFMs'></small><noframes id='kjFMs'>

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

        <tfoot id='kjFMs'></tfoot>
      2. 多个查询同一个表但在不同的列mysql

        时间:2023-08-18

        <small id='jACu5'></small><noframes id='jACu5'>

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

                1. 本文介绍了多个查询同一个表但在不同的列mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试从 2 个不同的表中获得更多的列汇总结果

                  I'm trying to get more columns summarizing the result from 2 different tables

                  SET @start_res = 20150301;
                  SET @finish_res= 20150501;
                  SET @finish_check= 20150801;
                  SET @start_check= 20150301;
                  SET @daily_hos= 3;
                  
                  SELECT* from
                     ( SELECT COUNT(DAY_IN) AS arr FROM t_hospital WHERE DAY_IN between  @start_check and @finish_check and RES_DATE between @start_res and @finish_res  and ID_daily_hos =@daily_hos group by DAY_IN  )e,
                       (SELECT COUNT(PAT_STATUS) AS ONG1 FROM t_hospital WHERE PAT_STATUS  like '%ong%' and  DAY_IN between @start_check and @finish_check and RES_DATE between @start_res and @finish_res  and ID_daily_hos =@daily_hos group by DAY_IN ) a,
                          (SELECT COUNT(PAT_STATUS) AS RTED FROM t_hospital WHERE PAT_STATUS  like '%rtde%'and  DAY_IN between  @start_check and @finish_check and RES_DATE between @start_res and @finish_res  and ID_daily_hos =@daily_hos group by DAY_IN  )b,
                             (SELECT COUNT(PAT_STATUS) AS POLI FROM t_hospital WHERE PAT_STATUS  like '%pol%'and DAY_IN between @start_check and @finish_check and RES_DATE between @start_res and @finish_res  and ID_daily_hos =@daily_hos group by DAY_IN   )c,
                                (SELECT COUNT(PAT_STATUS) AS para FROM t_hospital WHERE PAT_STATUS  like '%para%' and  DAY_IN between @start_check and @finish_check and RES_DATE between @start_res and @finish_res  and ID_daily_hos =@daily_hos group by DAY_IN  )d
                  

                  当然它不起作用,只有第一个显示的列 (arr) 起作用,而其他列显示错误的输出.

                  and of course it does not work, just the first displayed column (arr) works while the other ones show a wrong output.

                  我哪里错了?

                  推荐答案

                  这是一个很常见的模式:

                  This is a pretty common pattern:

                  SELECT DAY_IN, COUNT(*) AS arr,
                          SUM(IF(PAT_STATUS  like '%ong%', 1, 0)) AS ONG1,
                          SUM(IF(PAT_STATUS  like '%rtde%', 1, 0)) AS RTED,
                          SUM(IF(PAT_STATUS  like '%pol%', 1, 0)) AS POL1,
                          SUM(IF(PAT_STATUS  like '%para%', 1, 0)) AS para
                  FROM t_hospital 
                  WHERE DAY_IN between @start_check and @finish_check 
                      and RES_DATE between @start_res and @finish_res  
                      and ID_daily_hos =@daily_hos
                  GROUP BY DAY_IN
                  

                  这篇关于多个查询同一个表但在不同的列mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 MySQL 中进行递归 SELECT 查询? 下一篇:MySQL 错误 2006:mysql 服务器已消失

                  相关文章

                  最新文章

                  <tfoot id='XVXfl'></tfoot>

                    <legend id='XVXfl'><style id='XVXfl'><dir id='XVXfl'><q id='XVXfl'></q></dir></style></legend>

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

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