{"id":1,"date":"2025-04-27T17:40:19","date_gmt":"2025-04-27T09:40:19","guid":{"rendered":"https:\/\/lib.kimsor.top\/?p=1"},"modified":"2025-04-28T22:55:09","modified_gmt":"2025-04-28T14:55:09","slug":"hello-world","status":"publish","type":"post","link":"https:\/\/lib.kimsor.top\/?p=1","title":{"rendered":"SQL\u8fde\u8868\u5bfc\u81f4\u6570\u636e\u91cd\u590d\u95ee\u9898"},"content":{"rendered":"\n<p>sql\u8fde\u8868\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u91cd\u590d<\/p>\n\n\n\n<pre class=\"wp-block-code has-border-color has-pale-cyan-blue-background-color has-background\" style=\"border-color:#8ed1fc;border-width:16px;border-radius:19px\"><code>SELECT\n  SUM(c.patient_cost) allCost\nFROM patient_cost c\nLEFT JOIN patient_operation o ON c.patient_id = o.patient_id\nWHERE\n  o.operation_type = '\u4e09\u7ea7\u624b\u672f'<\/code><\/pre>\n\n\n\n<p>\u4f8b\uff1a<\/p>\n\n\n\n<p><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>patient_cost\u662f\u75c5\u4eba\u8d39\u7528\u8868<\/p>\n\n\n\n<p>patient_operation\u662f\u75c5\u4eba\u624b\u672f\u8868<\/p>\n<\/blockquote>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4e0a\u9762\u7684sql\u610f\u601d\u662f\u60f3\u83b7\u53d6\u505a\u8fc7\u4e09\u7ea7\u624b\u672f\u7684\u6240\u6709\u75c5\u4eba\u7684\u8d39\u7528\u4e4b\u548c\uff0cpatient_cost\u4e2d\u4fdd\u5b58\u7684\u662f\u75c5\u4eba\u7684\u8d39\u7528\uff0c\u4e00\u4e2a\u75c5\u4eba\u53ea\u6709\u4e00\u6761\u8bb0\u5f55\u3002\u4f46\u662f\u56e0\u4e3a\u4e00\u4e2a\u75c5\u4eba\u53ef\u80fd\u505a\u8fc7\u591a\u6b21\u624b\u672f\uff0c\u610f\u5473\u7740patient_operation\u4e2d\u4f1a\u6709\u591a\u6761\u8bb0\u5f55\u3002\u7ecf\u8fc7\u8fde\u8868\u4e4b\u540e\u5c31\u4f1a\u5bfc\u81f4\u8d39\u7528\u8bb0\u5f55\u53d8\u591a\uff0c\u6240\u4ee5\u4e0a\u9762\u7684sql\u6267\u884c\u540e\u4f1a\u5bfc\u81f4\u8d39\u7528\u589e\u591a<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528Distinct\u5b50\u67e5\u8be2\u53bb\u9664\u91cd\u590d\u8bb0\u5f55\u540e\u518d\u5904\u7406<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5bf9\u524d\u9762\u7684sql\u8fdb\u884c\u6539\u8fdb<\/p>\n\n\n\n<pre class=\"wp-block-code has-border-color has-pale-cyan-blue-background-color has-background\" style=\"border-color:#8ed1fc;border-width:16px;border-radius:19px\"><code>SELECT\n  SUM(t.patient_cost) allCost\nFROM\n(\nSELECT\n  distinct\n  c.patient_id,\n  c.patient_cost\nFROM patient_cost c\nLEFT JOIN patient_operation o ON c.patient_id = o.patient_id\nWHERE\n  o.operation_type = '\u4e09\u7ea7\u624b\u672f'\n) t<\/code><\/pre>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5bf9t\u5b50\u8868\u6211\u4eec\u5bf9\u67e5\u8be2\u51fa\u6765\u7684\u7ed3\u679c\u53ea\u53d6\u4e86\u60f3\u8981\u7684\u75c5\u4ebaid\u548c\u75c5\u4eba\u8d39\u7528\u6765\u53bb\u91cd\uff0c\u5176\u5b9e\u5c31\u662f\u5c06\u75c5\u4ebaid\u548c\u8d39\u7528\u5f53\u6210\u4e86\u552f\u4e00\u4e3b\u952e\uff0c\u6240\u4ee5\u7ecf\u8fc7\u53bb\u91cd\u4e4b\u540e\u7684t\u5b50\u8868\u5c31\u4fdd\u8bc1\u4e86\u4e00\u4e2a\u75c5\u4eba\u4e00\u6761\u8d39\u7528\u8bb0\u5f55\uff0c\u6700\u540e\u518d\u5bf9t\u8868\u4e2d\u7684\u7ed3\u679c\u8fdb\u884c\u8ba1\u7b97\u6c42\u548c\u5f97\u51fa\u6700\u7ec8\u8d39\u7528\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u90a3\u6240\u6709\u7684\u8fde\u8868\u90fd\u4f1a\u9020\u6210\u8bb0\u5f55\u91cd\u590d\u5417\uff1f<\/p>\n\n\n\n<p>\u7b54\u6848\uff1a\u5e76\u4e0d\u662f<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5982\u679c\u8fde\u8868\u6ee1\u8db3\u4e00\u5bf9\u4e00\u7684\u6761\u4ef6\uff0c\u90a3\u4e48\u5c31\u4e0d\u4f1a\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>sql\u8fde\u8868\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u91cd\u590d \u4f8b\uff1a patient_cost\u662f\u75c5\u4eba\u8d39\u7528\u8868 patient_operation\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,3],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-mysql","category-database"],"_links":{"self":[{"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1"}],"version-history":[{"count":6,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":33,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions\/33"}],"wp:attachment":[{"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}