{"id":4538,"date":"2019-11-02T14:46:14","date_gmt":"2019-11-02T06:46:14","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=4538"},"modified":"2019-11-02T14:46:14","modified_gmt":"2019-11-02T06:46:14","slug":"%e8%a7%a3%e5%86%b3-postgresql-%e6%8a%a5-error-for-select-distinct-order-by-expressions-must-appear-in-select-list","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4538","title":{"rendered":"\u89e3\u51b3 PostgreSQL \u62a5 ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">PostgreSQL \u8fd9\u4e24\u5e74\u72b9\u5982\u4e00\u5339\u9ed1\u9a6c\uff0c\u5728\u6570\u636e\u5e93\u9886\u57df\u589e\u957f\u901f\u5ea6\u8d85\u8fc7\u4e86 MySQL\uff0c\u5f53\u7136\u5728\u56fd\u5185 PostgreSQL \u7684\u793e\u533a\u5efa\u8bbe\u8fd8\u662f\u548c MySQL \u76f8\u5dee\u751a\u8fdc\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u8fd1\uff0c\u516c\u53f8\u91cc\u7684\u4e00\u4e2a\u8001\u65e7\u9879\u76ee\u7528\u5230\u4e86 PostgreSQL\uff0c\u6709\u4e00\u4e2a\u5c0f\u9700\u6c42\u9700\u8981\u6539\u52a8\u4e00\u4e0b\uff0c\u4e8e\u662f\u5206\u914d\u4e86\u4e00\u4e2a\u770b\u4f3c\u7b80\u5355\u7684\u4efb\u52a1\u7ed9\u5230\u4e86\u4e00\u4f4d\u65b0\u540c\u4e8b\uff0c\u8c01\u77e5\u8fd9\u4e2a\u521d\u51fa\u8305\u5e90\u7684\u65b0\u540c\u4e8b\u628a\u95ee\u9898\u53c8\u629b\u7ed9\u6211\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u95ee\u9898\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u5728\u6267\u884c SQL \u65f6\uff0c\u5f53 DISTINCT \u548c ORDER BY \u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u62a5\u51fa\u4e86\u201cERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list\u201c\u5f02\u5e38\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u5f02\u5e38\u5f88\u7b80\u5355\uff0c\u6839\u636e\u5b57\u9762\u610f\u601d\u6211\u4eec\u5c31\u53ef\u4ee5\u77e5\u9053\uff0c\u5b83\u8bf4\u7684\u5927\u81f4\u610f\u601d\u662f\u8bf4\uff0c\u9700\u8981\u5c06 ORDER BY \u4e2d\u7684\u5b57\u6bb5\u6dfb\u52a0\u5230 SELECT \u5217\u8868\u4e2d\u3002\u8bf4\u767d\u4e86\uff0c\u5c31\u662f\u8ba9 ORDER BY \u7684\u5b57\u6bb5\uff0c\u52a0\u5230 select DISTINCT \u4e2d\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT DISTINCT author,status,create_time FROM xttblog ORDER BY create_time DESC;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u4e0a\u9762\u8fd9\u4e2a\u8bed\u53e5\uff0c\u5982\u679c\u4e0d\u628a create_time \u5b57\u6bb5\u6dfb\u52a0\u5230 SELECT DISTINCT \u2026 FROM \u4e4b\u95f4\u7684\u8bdd\uff0c\u6267\u884c\u65f6\u5c31\u4f1a\u62a5\u6807\u9898\u4e2d\u7684\u9519\u8bef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\uff0c\u5e0c\u671b\u80fd\u591f\u5e2e\u52a9\u5230\u4e00\u4e9b\u65b0\u4eba\u7a0b\u5e8f\u5458\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4538\">\u89e3\u51b3 PostgreSQL \u62a5 ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>PostgreSQL \u8fd9\u4e24\u5e74\u72b9\u5982\u4e00\u5339\u9ed1\u9a6c\uff0c\u5728\u6570\u636e\u5e93\u9886\u57df\u589e\u957f\u901f\u5ea6\u8d85\u8fc7\u4e86 MySQL\uff0c\u5f53\u7136\u5728\u56fd\u5185 PostgreS [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[2024,83,2025,429,681],"class_list":["post-4538","post","type-post","status-publish","format-standard","hentry","category-sql","tag-distinct","tag-mysql","tag-order-by","tag-postgresql","tag-681"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4538"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4538\/revisions"}],"predecessor-version":[{"id":4539,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4538\/revisions\/4539"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}