{"id":7030,"date":"2024-11-14T11:21:24","date_gmt":"2024-11-14T03:21:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7030\/"},"modified":"2024-11-14T11:21:24","modified_gmt":"2024-11-14T03:21:24","slug":"%e5%a6%82%e4%bd%95%e4%b8%ba%e6%b2%a1%e6%9c%89%e5%85%b3%e8%81%94%e8%ae%b0%e5%bd%95%e7%9a%84-strategy-%e6%98%be%e7%a4%ba%e7%a9%ba%e5%80%bc%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7030\/","title":{"rendered":"\u5982\u4f55\u4e3a\u6ca1\u6709\u5173\u8054\u8bb0\u5f55\u7684 Strategy \u663e\u793a\u7a7a\u503c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173033570265565.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4e3a\u6ca1\u6709\u5173\u8054\u8bb0\u5f55\u7684 Strategy \u663e\u793a\u7a7a\u503c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4e3a\u6ca1\u6709\u5173\u8054\u8bb0\u5f55\u7684 Strategy \u663e\u793a\u7a7a\u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u8054\u5408\u67e5\u8be2\u96be\u9898\uff1a\u4e3a\u6ca1\u6709\u5173\u8054\u7684\u8bb0\u5f55\u663e\u793a\u7a7a\u503c<\/strong><\/p>\n<p>\u4f5c\u4e3a\u4e00\u540d\u6570\u636e\u5e93\u65b0\u624b\uff0c\u6211\u9047\u5230\u4e00\u4e2a\u8054\u5408\u67e5\u8be2\u95ee\u9898\uff0c\u5e0c\u671b\u5f97\u5230\u5404\u4f4d\u5927\u4f6c\u7684\u6307\u5bfc\u3002<\/p>\n<p>\u6211\u4eec\u6709\u4e09\u4e2a\u8868\uff1astrategy\u3001group \u548c strategy_group\u3002strategy_group \u662f strategy \u548c group \u7684 id \u5bf9\u5e94\u8868\uff0c\u8bb0\u5f55\u7740\u54ea\u4e9b strategy \u5c5e\u4e8e\u54ea\u4e9b group\u3002\u6211\u7684\u67e5\u8be2\u76ee\u6807\u662f\u83b7\u53d6\u6240\u6709 strategy \u7684\u4fe1\u606f\uff0c\u4ee5\u53ca\u76f8\u5e94\u7684 group \u4e2d\u7684 gatewaymac \u5b57\u6bb5\u3002<\/p>\n<p>\u6211\u5c1d\u8bd5\u7f16\u5199\u4e86\u4ee5\u4e0b\u67e5\u8be2\u8bed\u53e5\uff1a<\/p>\n<pre>select * from strategy as s\ninner join strategy_group as sg on s.id = sg.strategy_id\ninner join group as g on sg.group_id = g.id<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f46\u662f\uff0c\u8fd9\u4e2a\u67e5\u8be2\u53ea\u8fd4\u56de\u4e86\u6709 group \u5173\u8054\u7684 strategy \u8bb0\u5f55\u3002\u6211\u60f3\u77e5\u9053\u5982\u4f55\u5c06\u90a3\u4e9b\u6ca1\u6709 group \u8054\u7cfb\u7684 strategy \u4fe1\u606f\u4e5f\u663e\u793a\u51fa\u6765\uff0c\u5e76\u4e14\u5c06 gatewaymac \u503c\u8bbe\u4e3a\u7a7a\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 left join \u800c\u4e0d\u662f inner join \u6765\u89e3\u51b3\u3002left join \u4f1a\u4fdd\u7559\u88ab\u62fc\u8868\u5b57\u6bb5\u4e3a\u7a7a\u7684\u6570\u636e\uff0c\u800c inner join \u5219\u53ea\u4fdd\u7559\u6709\u5339\u914d\u6570\u636e\u7684\u884c\u3002<\/p>\n<p>\u4fee\u6539\u540e\u7684\u67e5\u8be2\u8bed\u53e5\uff1a<\/p>\n<pre>SELECT *, \n   IF(gatewaymac IS NULL, 'defaultValue', gatewaymac) gatewaymac\nFROM strategy AS s\nLEFT JOIN strategy_group AS sg ON s.id = sg.strategy_id\nLEFT JOIN group AS g ON sg.group_id = g.id<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd9\u4e2a\u67e5\u8be2\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 if() \u51fd\u6570\u5c06 gatewaymac \u5b57\u6bb5\u7684\u503c\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u9ed8\u8ba4\u503c\uff08\u4f8b\u5982 &#8216;defaultvalue&#8217;\uff09\uff0c\u5982\u679c\u5b83\u4e3a\u7a7a\u3002\u8fd9\u6837\uff0c\u90a3\u4e9b\u6ca1\u6709 group \u5173\u8054\u7684 strategy \u8bb0\u5f55\u4e5f\u4e0d\u4f1a\u88ab\u9057\u6f0f\uff0c\u5e76\u4e14 gatewaymac \u5b57\u6bb5\u4f1a\u663e\u793a\u4e3a\u7a7a\u503c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4e3a\u6ca1\u6709\u5173\u8054\u8bb0\u5f55\u7684 Strategy \u663e\u793a\u7a7a\u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8054\u5408\u67e5\u8be2\u96be\u9898\uff1a\u4e3a\u6ca1\u6709\u5173\u8054\u7684\u8bb0\u5f55\u663e\u793a\u7a7a\u503c \u4f5c\u4e3a\u4e00\u540d\u6570\u636e\u5e93\u65b0\u624b\uff0c\u6211\u9047\u5230\u4e00\u4e2a\u8054\u5408\u67e5\u8be2\u95ee\u9898\uff0c\u5e0c\u671b\u5f97\u5230\u5404\u4f4d\u5927\u4f6c\u7684\u6307\u5bfc\u3002 \u6211\u4eec\u6709\u4e09\u4e2a\u8868\uff1astrategy\u3001group \u548c strategy_group\u3002strategy_group \u662f strategy \u548c group \u7684 id \u5bf9\u5e94\u8868\uff0c\u8bb0\u5f55\u7740\u54ea\u4e9b strategy \u5c5e\u4e8e\u54ea\u4e9b group\u3002\u6211\u7684\u67e5\u8be2\u76ee\u6807\u662f\u83b7\u53d6\u6240\u6709 strategy \u7684\u4fe1\u606f\uff0c\u4ee5\u53ca\u76f8\u5e94\u7684 group \u4e2d\u7684 gatewaymac \u5b57\u6bb5\u3002 \u6211\u5c1d\u8bd5\u7f16\u5199\u4e86\u4ee5\u4e0b\u67e5\u8be2\u8bed\u53e5\uff1a select * from strategy as s inner join strategy_group as sg on s.id = sg.strategy_id inner join group as g on sg.group_id = g.id \u767b\u5f55\u540e\u590d\u5236 \u4f46\u662f\uff0c\u8fd9\u4e2a\u67e5\u8be2\u53ea\u8fd4\u56de\u4e86\u6709 group \u5173\u8054\u7684 strategy \u8bb0\u5f55\u3002\u6211\u60f3\u77e5\u9053\u5982\u4f55\u5c06\u90a3\u4e9b\u6ca1\u6709 group \u8054\u7cfb\u7684 strategy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7030","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7030"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7030\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}