久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='qeO13'><style id='qeO13'><dir id='qeO13'><q id='qeO13'></q></dir></style></legend>
<tfoot id='qeO13'></tfoot>
      • <bdo id='qeO13'></bdo><ul id='qeO13'></ul>
    1. <small id='qeO13'></small><noframes id='qeO13'>

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

        在 MYSQL 中加入帶有 SUM 問題的表

        Join tables with SUM issue in MYSQL(在 MYSQL 中加入帶有 SUM 問題的表)
        1. <tfoot id='L9y3w'></tfoot>

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

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

                • <legend id='L9y3w'><style id='L9y3w'><dir id='L9y3w'><q id='L9y3w'></q></dir></style></legend>
                  本文介紹了在 MYSQL 中加入帶有 SUM 問題的表的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我一直在獲取連接表上的 SUM 時(shí)遇到問題,總是有問題,我可以通過運(yùn)行兩個(gè)查詢來獲得我需要的結(jié)果,我想知道這兩個(gè)查詢是否可以組合成一個(gè)連接查詢,這里是我的查詢以及我加入查詢的嘗試

                  I have always had trouble getting SUMs on join tables, there is always an issue, I can get the results I need by running two queries, I am wondering if this two queries can be combine to make one join query, here is the queries I have and my attempt to join the query

                  查詢 1

                  SELECT last_name, first_name, DATE_FORMAT( (mil_date),  '%m/%d/%y' ) AS dates, 
                  SUM( drive_time ) MINUTES FROM bhds_mileage LEFT JOIN bhds_teachers i 
                  ON i.ds_id = bhds_mileage.ds_id 
                  WHERE mil_date BETWEEN  '2016-04-11' AND  '2016-04-30'
                  AND bhds_mileage.ds_id =5
                  GROUP BY CONCAT( YEAR( mil_date ) ,  '/', WEEK( mil_date ) ) ,    
                  bhds_mileage.ds_id
                  ORDER BY last_name ASC , dates ASC 
                  

                  以分鐘為單位的輸出是271,281,279

                  the output in minutes is 271, 281, 279

                  查詢 2

                  SELECT last_name, first_name, DATE_FORMAT((tm_date), '%m/%d/%y') AS dates,   
                  SUM(tm_hours) total FROM bhds_timecard LEFT JOIN bhds_teachers i 
                  ON i.ds_id = bhds_timecard.ds_id 
                  WHERE tm_date BETWEEN '2016-04-11' AND '2016-04-30' AND bhds_timecard.ds_id = 5
                  GROUP BY CONCAT(YEAR(tm_date), '/', WEEK(tm_date)), bhds_timecard.ds_id 
                  ORDER BY last_name ASC, dates ASC
                  

                  這里的輸出是 33.00, 36.00, 26.75

                  The output here is 33.00, 36.00, 26.75

                  現(xiàn)在我嘗試加入查詢

                  SELECT last_name, first_name, DATE_FORMAT((tm_date), '%m/%d/%y') AS dates,  
                  SUM(tm_hours) total,  SUM( drive_time ) MINUTES FROM bhds_timecard 
                  LEFT JOIN bhds_teachers i ON i.ds_id = bhds_timecard.ds_id 
                  LEFT JOIN bhds_mileage ON DATE_FORMAT((bhds_timecard.tm_date), '%m/%d/%y') = 
                  DATE_FORMAT((bhds_mileage.mil_date), '%m/%d/%y') AND bhds_timecard.ds_id = bhds_mileage.ds_id
                  WHERE tm_date BETWEEN '2016-04-11' AND '2016-04-30' AND bhds_timecard.ds_id = 5
                  GROUP BY CONCAT(YEAR(tm_date), '/', WEEK(tm_date)), bhds_timecard.ds_id 
                  

                  括號(hào)是預(yù)期的

                  輸出 1044 (271), 1086 (281), 1215 (279)

                  this outputs 1044 (271), 1086 (281), 1215 (279)

                  推薦答案

                  當(dāng)您在主查詢中使用多個(gè)連接時(shí),您最終會(huì)得到所有表的叉積,因此總和乘以匹配的行數(shù)在另一張桌子上.您需要將總和移動(dòng)到子查詢中.

                  When you use multiple joins in the main query, you end up with a cross product of all the tables, so the sums get multiplied by the number of rows matching in another table. You need to move the sums into subqueries.

                  SELECT last_name, first_name, DATE_FORMAT(LEAST(mil_date, tm_date),  '%m/%d/%y' ) AS dates, 
                          total, minutes
                  FROM bhds_teachers AS i
                  LEFT JOIN (
                      SELECT ds_id, YEARWEEK(mil_date) AS week, MIN(mil_date) AS mil_date, SUM(drive_time) AS minutes
                      FROM bhds_mileage
                      WHERE mil_date BETWEEN '2016-04-11' AND  '2016-04-30'
                      AND bhds_mileage.ds_id = 5
                      GROUP BY ds_id, week) AS m 
                  ON m.ds_id = i.ds_id
                  LEFT JOIN (
                      SELECT ds_id, YEARWEEK(tm_date) AS week, MIN(tm_date) AS tm_date, SUM(tm_hours) AS total
                      WHERE tm_date BETWEEN '2016-04-11' AND '2016-04-30' AND bhds_timecard.ds_id = 5
                      GROUP BY ds_id, week) AS t 
                  ON t.ds_id = i.ds_id AND t.week = m.week
                  

                  這篇關(guān)于在 MYSQL 中加入帶有 SUM 問題的表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Break down a table to pivot in columns (SQL,PYSPARK)(分解表以按列進(jìn)行透視(SQL、PYSPARK))
                  Dropping MySQL table with SparkSQL(使用 SparkSQL 刪除 MySQL 表)
                  Spark giving Null Pointer Exception while performing jdbc save(Spark在執(zhí)行jdbc保存時(shí)給出空指針異常)
                  execute query on sqlserver using spark sql(使用 spark sql 在 sqlserver 上執(zhí)行查詢)
                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數(shù)根據(jù) N 個(gè)先前值來決定接下來的 N 個(gè)行)
                  Spark SQL/Hive Query Takes Forever With Join(Spark SQL/Hive 查詢永遠(yuǎn)需要加入)

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

                          1. 主站蜘蛛池模板: 国产欧美精品 | 国产精品免费在线 | com.国产| 国产精品18久久久久久白浆动漫 | 日韩精品一区二区三区免费观看 | 国产精品1区| 另类视频区 | 999热精品 | 精品久久久久久久久久久 | 精品中文字幕在线 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 成人免费在线观看视频 | 欧美a在线| 免费三级黄 | 国产精品久久久久久久久久久久久久 | 久草视频观看 | 日韩综合网| 精品福利在线 | 日韩一区二区av | 国产精品不卡 | 99热在这里只有精品 | 91在线导航| 欧美精品一区三区 | 国产一级特黄真人毛片 | 中文在线一区 | 日韩免费 | 99福利视频导航 | 国产视频二区 | 成人在线精品视频 | 在线国产一区 | 欧美一区二区三区在线视频 | 久久不射电影网 | 国产成人在线一区二区 | 99久热在线精品视频观看 | 狠狠久久综合 | 9999国产精品欧美久久久久久 | 国产精品免费小视频 | 国产一区二区三区在线看 | 欧美精品一区二区免费视频 | 播放一级黄色片 | 欧美精品a∨在线观看不卡 国产精品久久国产精品 |