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

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

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

    2. mySQL 和 postgreSQL 中的 Group by 子句,為什么 postg

      Group by clause in mySQL and postgreSQL, why the error in postgreSQL?(mySQL 和 postgreSQL 中的 Group by 子句,為什么 postgreSQL 會出錯?)
      <tfoot id='wDGej'></tfoot>
        <legend id='wDGej'><style id='wDGej'><dir id='wDGej'><q id='wDGej'></q></dir></style></legend>

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

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

                <tbody id='wDGej'></tbody>

              1. 本文介紹了mySQL 和 postgreSQL 中的 Group by 子句,為什么 postgreSQL 會出錯?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                假設我有這個表:named = the_table其結構為:

                postgreSQL:

                 create table the_table (col3 SERIAL, col2 varchar, col1 varchar, PRIMARY KEY(col3));

                MySQL:

                create table the_table ( col3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, col2 varchar(20), col1 varchar(20) )

                然后我插入了表格:

                INSERT INTO the_table (col2,col1) VALUES('x','a'),('x','b'),('y','c'),('y','d'),('z','e'),('z','f');

                現在表格如下所示:

                col3 |col2 |第 1 列------+------+------1 |× |一種2 |× |乙3 |是 |C4 |是 |d5 || |電子6 || |F

                當我做這個查詢時:

                select * from the_table group by col2

                然后在mysql中我得到:

                1 x a3 年5澤

                在 postgreSQL 中,我收到錯誤:

                錯誤:列the_table.col3"必須出現在 GROUP BY 子句中或用于聚合函數中LINE 1: select * from the_table group by col2;

                我的問題:

                這個錯誤是什么意思?什么是聚合函數?

                當它在 MySQL 中工作時,為什么它不能在 postgreSQL 中工作?

                解決方案

                您需要使用 聚合函數:

                <塊引用>

                聚合函數從一組輸入計算單個結果值.

                SELECT col2, MIN(col3) AS col3, MIN(col1) AS col1FROM the_table按 col2 分組;

                db<>小提琴演示<小時><塊引用>

                MySQL 處理 GROUP BY:

                在標準 SQL 中,包含 GROUP BY 子句的查詢不能引用到選擇列表中未命名的非聚合列GROUP BY 子句

                和:

                <塊引用>

                MySQL 擴展了 GROUP BY 的使用,以便選擇列表可以引用未在 GROUP BY 子句中命名的非聚合列.這意味著前面的查詢在 MySQL 中是合法的.您可以使用此功能通過避免不必要的列排序和分組來獲得更好的性能.但是,這主要在未在 GROUP BY 中命名的每個非聚合列中的所有值對于每個組都相同時很有用.服務器可以自由地從每個組中選擇任何值,因此除非它們相同,否則選擇的值是不確定的

                因此,對于沒有顯式聚合函數的 MySQL 版本,您最終可能會得到不確定的值.我強烈建議使用特定的聚合函數.

                <小時>

                來自 MySQL 對 GROUP BY 的處理:

                <塊引用>

                SQL92 及更早版本不允許查詢的選擇列表、HAVING 條件或 ORDER BY 列表引用未在 GROUP BY 子句中命名的非聚合列.

                SQL99 和更高版本允許每個可選功能 T301 的此類非聚合如果它們在功能上依賴于 GROUP BY 列:如果在 name 和 custid 之間存在這種關系,則查詢是合法的.例如,如果是客戶的主鍵,就會出現這種情況.

                示例:

                SELECT o.custid, c.name, MAX(o.payment)FROM 訂單 AS o加入客戶作為 cON o.custid = c.custidGROUP BY o.custid;

                Suppose I have this table: named = the_table whose structure is:

                postgreSQL:

                 create table the_table (col3 SERIAL, col2 varchar, col1 varchar, PRIMARY KEY(col3));
                

                MySQL:

                create table the_table ( col3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, col2 varchar(20), col1 varchar(20) )
                

                Then I inserted the table:

                INSERT INTO the_table (col2,col1) VALUES 
                ('x','a'),
                ('x','b'),
                ('y','c'),
                ('y','d'),
                ('z','e'),
                ('z','f');
                

                Now the table looks like this:

                col3 | col2 | col1 
                ------+------+------
                    1 | x    | a
                    2 | x    | b
                    3 | y    | c
                    4 | y    | d
                    5 | z    | e
                    6 | z    | f
                

                When I do this query:

                select * from the_table group by col2
                

                then in mysql I get:

                1 x a
                3 y c
                5 z e
                

                and in postgreSQL, I am getting error:

                ERROR:  column "the_table.col3" must appear in the GROUP BY clause or be used in an aggregate function
                LINE 1: select * from the_table group by col2;
                

                My Questions:

                What does this error mean? What is aggregate function ?

                When it works in MySQL , why can't it work in postgreSQL ?

                解決方案

                You need to use AGGREGATE FUNCTION:

                Aggregate functions compute a single result from a set of input values.

                SELECT col2, MIN(col3) AS col3, MIN(col1) AS col1
                FROM the_table 
                GROUP BY col2;
                

                db<>fiddle demo


                MySQL Handling of GROUP BY:

                In standard SQL, a query that includes a GROUP BY clause cannot refer to nonaggregated columns in the select list that are not named in the GROUP BY clause

                and:

                MySQL extends the use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BY clause. This means that the preceding query is legal in MySQL. You can use this feature to get better performance by avoiding unnecessary column sorting and grouping. However, this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate

                So with MySQL version without explicit aggregate function you may end up with undetermininistic values. I strongly suggest to use specific aggregate function.


                EDIT:

                From MySQL Handling of GROUP BY:

                SQL92 and earlier does not permit queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are not named in the GROUP BY clause.

                SQL99 and later permits such nonaggregates per optional feature T301 if they are functionally dependent on GROUP BY columns: If such a relationship exists between name and custid, the query is legal. This would be the case, for example, were custid a primary key of customers.

                Example:

                SELECT o.custid, c.name, MAX(o.payment)
                FROM orders AS o
                JOIN customers AS c
                  ON o.custid = c.custid
                GROUP BY o.custid;
                

                這篇關于mySQL 和 postgreSQL 中的 Group by 子句,為什么 postgreSQL 會出錯?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)

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

                  <tbody id='BkTtf'></tbody>
                  <bdo id='BkTtf'></bdo><ul id='BkTtf'></ul>

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

                      <legend id='BkTtf'><style id='BkTtf'><dir id='BkTtf'><q id='BkTtf'></q></dir></style></legend>
                      • <tfoot id='BkTtf'></tfoot>

                          主站蜘蛛池模板: 亚洲高清视频一区二区 | 在线午夜 | 精品国产91 | 午夜精品网站 | 久久高清免费视频 | 福利网址 | 欧美第一页 | 午夜久久久久久久久久一区二区 | 天天干天天爱天天 | 999视频| 亚洲精品一区中文字幕乱码 | 亚洲精品久久久久国产 | 天天色天天射天天干 | 久久精品小视频 | 欧美另类视频在线 | 国产精品欧美一区二区三区不卡 | 国产精品日本一区二区在线播放 | 麻豆91av | 久国久产久精永久网页 | 亚洲免费成人av | 中文字幕在线一区 | 久久久久久国产精品免费免费狐狸 | 国产精品国产a | 蜜桃视频一区二区三区 | 不卡一区二区三区四区 | 日韩精品免费视频 | 九九国产| 国产在线一区二区三区 | 成人久久18免费网站图片 | 日韩欧美在线视频 | 色婷婷精品 | 日韩中文字幕 | 国产成人亚洲精品 | 国产精品久久久久久久久久久久久久 | 精品免费国产一区二区三区四区介绍 | 午夜精品在线 | 人人做人人澡人人爽欧美 | 日韩一级精品视频在线观看 | 国产高清自拍视频在线观看 | 亚洲免费在线 | 欧美电影免费观看高清 |