{"id":611,"date":"2024-12-28T18:45:23","date_gmt":"2024-12-28T10:45:23","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=611"},"modified":"2024-12-28T18:45:23","modified_gmt":"2024-12-28T10:45:23","slug":"%e9%9d%9e%e5%b8%b8%e9%80%82%e5%90%88%e5%b0%8f%e7%99%bd%e5%ad%a6%e4%bc%9a%ef%bc%9asql%e7%aa%97%e5%8f%a3%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2024\/12\/28\/%e9%9d%9e%e5%b8%b8%e9%80%82%e5%90%88%e5%b0%8f%e7%99%bd%e5%ad%a6%e4%bc%9a%ef%bc%9asql%e7%aa%97%e5%8f%a3%e5%87%bd%e6%95%b0\/","title":{"rendered":"\u975e\u5e38\u9002\u5408\u5c0f\u767d\u5b66\u4f1a\uff1aSQL\u7a97\u53e3\u51fd\u6570"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u5e2e\u52a9\u4f60\u66f4\u8be6\u7ec6\u3001\u6e05\u6670\u5730\u7406\u89e3 SQL \u7a97\u53e3\u51fd\u6570\uff0c\u672c\u6587\u4ece\u96f6\u5f00\u59cb\u8be6\u7ec6\u89e3\u91ca\uff0c\u5e76\u901a\u8fc7\u9010\u6b65\u793a\u4f8b\u6765\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u3002\u7a97\u53e3\u51fd\u6570\u53ef\u4ee5\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\u5927\u5927\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff0c\u5e2e\u52a9\u4f60\u4ece\u4e0d\u540c\u89d2\u5ea6\u7406\u89e3\u6570\u636e\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4ec0\u4e48\u662f\u7a97\u53e3\u51fd\u6570\uff1f<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a97\u53e3\u51fd\u6570\u662f SQL \u4e2d\u7684\u4e00\u7c7b\u7279\u6b8a\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u57fa\u4e8e\u67e5\u8be2\u7ed3\u679c\u96c6\u7684\u67d0\u4e9b\u90e8\u5206\uff08\u7a97\u53e3\uff09\u6765\u8ba1\u7b97\u67d0\u4e9b\u805a\u5408\u503c\u6216\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\u3002\u4e0d\u540c\u4e8e\u666e\u901a\u7684\u805a\u5408\u51fd\u6570\uff08\u5982 <code>SUM()<\/code>\u3001<code>AVG()<\/code>\u3001<code>COUNT()<\/code> \u7b49\uff09\uff0c\u7a97\u53e3\u51fd\u6570\u4e0d\u4f1a\u5bf9\u6570\u636e\u8fdb\u884c\u201c\u6c47\u603b\u201d\uff0c\u800c\u662f\u4fdd\u7559\u6bcf\u4e00\u884c\u6570\u636e\uff0c\u5e76\u5728\u8be5\u884c\u5468\u56f4\u7684\u201c\u7a97\u53e3\u201d\u4e2d\u6267\u884c\u8ba1\u7b97\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. \u57fa\u672c\u8bed\u6cd5<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a97\u53e3\u51fd\u6570\u7684\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;\u7a97\u53e3\u51fd\u6570&gt; OVER (PARTITION BY &lt;\u5206\u7ec4\u5b57\u6bb5&gt; ORDER BY &lt;\u6392\u5e8f\u5b57\u6bb5&gt;)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7a97\u53e3\u51fd\u6570<\/strong>\uff1a\u8fd9\u662f\u4f60\u60f3\u6267\u884c\u7684\u5177\u4f53\u64cd\u4f5c\uff0c\u4f8b\u5982\uff1a<code>ROW_NUMBER()<\/code>, <code>RANK()<\/code>, <code>SUM()<\/code>, <code>AVG()<\/code> \u7b49\u3002<\/li>\n\n\n\n<li><strong>OVER()<\/strong>\uff1a\u8868\u793a\u7a97\u53e3\u51fd\u6570\u5c06\u5728\u6b64\u8bed\u53e5\u4e2d\u88ab\u5e94\u7528\u3002<\/li>\n\n\n\n<li><strong>PARTITION BY<\/strong>\uff1a\u6307\u5b9a\u5982\u4f55\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\u3002\u7c7b\u4f3c\u4e8e <code>GROUP BY<\/code>\uff0c\u4f46\u7a97\u53e3\u51fd\u6570\u4f1a\u4fdd\u6301\u6bcf\u4e00\u884c\u6570\u636e\uff0c\u53ea\u662f\u5728\u5206\u7ec4\u5185\u8ba1\u7b97\u3002<\/li>\n\n\n\n<li><strong>ORDER BY<\/strong>\uff1a\u6307\u5b9a\u5982\u4f55\u5bf9\u6bcf\u4e2a\u5206\u7ec4\u5185\u7684\u6570\u636e\u8fdb\u884c\u6392\u5e8f\u3002\u6392\u5e8f\u5f71\u54cd\u6392\u540d\u548c\u5176\u4ed6\u8ba1\u7b97\u7ed3\u679c\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. \u5e38\u89c1\u7684\u7a97\u53e3\u51fd\u6570\u53ca\u793a\u4f8b<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>ROW_NUMBER()<\/strong> &#8211; \u7ed9\u6bcf\u4e00\u884c\u6570\u636e\u6392\u5e8f\u5e76\u8fd4\u56de\u552f\u4e00\u7684\u884c\u53f7<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ROW_NUMBER()<\/code> \u662f\u4e00\u4e2a\u6700\u5e38\u89c1\u7684\u7a97\u53e3\u51fd\u6570\uff0c\u5b83\u7ed9\u6bcf\u4e00\u884c\u6570\u636e\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684\u7f16\u53f7\u3002\u5e38\u7528\u4e8e\u5bf9\u6570\u636e\u6309\u67d0\u4e2a\u5b57\u6bb5\u6392\u5e8f\u5e76\u7ed9\u6bcf\u884c\u6570\u636e\u6dfb\u52a0\u6392\u540d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n    id, \n    name, \n    salary, \n    ROW_NUMBER() OVER (ORDER BY salary DESC) AS row_num\nFROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u91ca<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ROW_NUMBER()<\/code> \u5c06\u4f1a\u4e3a\u6bcf\u4e00\u884c\u5458\u5de5\u6570\u636e\u6309\u85aa\u8d44\uff08<code>salary DESC<\/code>\uff09\u6392\u5e8f\uff0c\u5e76\u7ed9\u6bcf\u4e00\u884c\u6dfb\u52a0\u4e00\u4e2a\u552f\u4e00\u7684\u884c\u53f7\u3002<\/li>\n\n\n\n<li>\u6392\u540d\u4ece 1 \u5f00\u59cb\uff0c\u5982\u679c\u6709\u591a\u4e2a\u5458\u5de5\u7684\u85aa\u8d44\u76f8\u540c\uff0c\u4ed6\u4eec\u7684\u884c\u53f7\u4e5f\u4f1a\u6839\u636e\u6392\u5e8f\u89c4\u5219\u5206\u914d\u4e0d\u540c\u7684\u7f16\u53f7\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ed3\u679c\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>id<\/th><th>name<\/th><th>salary<\/th><th>row_num<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>\u5f20\u4e09<\/td><td>9000<\/td><td>1<\/td><\/tr><tr><td>2<\/td><td>\u674e\u56db<\/td><td>8500<\/td><td>2<\/td><\/tr><tr><td>3<\/td><td>\u738b\u4e94<\/td><td>8500<\/td><td>3<\/td><\/tr><tr><td>4<\/td><td>\u8d75\u516d<\/td><td>7000<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>RANK()<\/strong> &#8211; \u7ed9\u6570\u636e\u6392\u540d\uff0c\u6392\u540d\u76f8\u540c\u7684\u884c\u8df3\u8fc7<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>RANK()<\/code> \u51fd\u6570\u548c <code>ROW_NUMBER()<\/code> \u76f8\u4f3c\uff0c\u4f46\u5982\u679c\u6709\u76f8\u540c\u503c\u7684\u6570\u636e\uff0c\u5b83\u4eec\u4f1a\u5f97\u5230\u76f8\u540c\u7684\u6392\u540d\uff0c\u5e76\u8df3\u8fc7\u4e0b\u4e00\u4e2a\u6392\u540d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n    id, \n    name, \n    salary, \n    RANK() OVER (ORDER BY salary DESC) AS rank\nFROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u91ca<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>RANK()<\/code> \u4f1a\u6839\u636e\u85aa\u8d44\u4e3a\u5458\u5de5\u6392\u540d\uff0c\u4f46\u5f53\u591a\u4e2a\u5458\u5de5\u7684\u85aa\u8d44\u76f8\u540c\uff0c\u4ed6\u4eec\u7684\u6392\u540d\u4f1a\u76f8\u540c\uff08\u5982 1 \u548c 2\uff09\uff0c\u800c\u4e0b\u4e00\u4e2a\u6392\u540d\u4f1a\u8df3\u8fc7\u4e00\u4e2a\u6570\u5b57\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ed3\u679c\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>id<\/th><th>name<\/th><th>salary<\/th><th>rank<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>\u5f20\u4e09<\/td><td>9000<\/td><td>1<\/td><\/tr><tr><td>2<\/td><td>\u674e\u56db<\/td><td>8500<\/td><td>2<\/td><\/tr><tr><td>3<\/td><td>\u738b\u4e94<\/td><td>8500<\/td><td>2<\/td><\/tr><tr><td>4<\/td><td>\u8d75\u516d<\/td><td>7000<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>DENSE_RANK()<\/strong> &#8211; \u7ed9\u6570\u636e\u6392\u540d\uff0c\u6392\u540d\u76f8\u540c\u7684\u884c\u4e0d\u8df3\u8fc7<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>DENSE_RANK()<\/code> \u4e5f\u662f\u4e3a\u6570\u636e\u6392\u540d\uff0c\u4f46\u5b83\u4e0d\u4f1a\u8df3\u8fc7\u6392\u540d\u3002\u5982\u679c\u6709\u4e24\u4e2a\u76f8\u540c\u7684\u85aa\u8d44\uff0c\u4ed6\u4eec\u4f1a\u5f97\u5230\u76f8\u540c\u7684\u6392\u540d\uff0c\u4e0b\u4e00\u4e2a\u6392\u540d\u4e0d\u4f1a\u8df3\u8fc7\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n    id, \n    name, \n    salary, \n    DENSE_RANK() OVER (ORDER BY salary DESC) AS dense_rank\nFROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u91ca<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>DENSE_RANK()<\/code> \u5bf9\u4e8e\u540c\u6837\u7684\u503c\u4f1a\u7ed9\u51fa\u76f8\u540c\u7684\u6392\u540d\uff0c\u4f46\u662f\u4e0d\u4f1a\u8df3\u8fc7\u4e0b\u4e00\u4e2a\u6392\u540d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ed3\u679c\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>id<\/th><th>name<\/th><th>salary<\/th><th>dense_rank<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>\u5f20\u4e09<\/td><td>9000<\/td><td>1<\/td><\/tr><tr><td>2<\/td><td>\u674e\u56db<\/td><td>8500<\/td><td>2<\/td><\/tr><tr><td>3<\/td><td>\u738b\u4e94<\/td><td>8500<\/td><td>2<\/td><\/tr><tr><td>4<\/td><td>\u8d75\u516d<\/td><td>7000<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>NTILE()<\/strong> &#8211; \u5c06\u6570\u636e\u5206\u6210 N \u4e2a\u7ec4<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>NTILE()<\/code> \u7528\u6765\u5c06\u6570\u636e\u5206\u6210\u82e5\u5e72\u4e2a\u7ec4\uff08\u4f8b\u5982\u56db\u5206\u4f4d\uff09\uff0c\u5e76\u8fd4\u56de\u6bcf\u884c\u6240\u5c5e\u7684\u7ec4\u53f7\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n    id, \n    name, \n    salary, \n    NTILE(4) OVER (ORDER BY salary DESC) AS quartile\nFROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u91ca<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>NTILE(4)<\/code> \u5c06\u5458\u5de5\u6570\u636e\u6839\u636e\u85aa\u8d44\u964d\u5e8f\u6392\u5e8f\uff0c\u5e76\u5206\u6210 4 \u4e2a\u7ec4\uff0c\u8fd4\u56de\u6bcf\u4e2a\u5458\u5de5\u6240\u5728\u7684\u7ec4\u53f7\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ed3\u679c\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>id<\/th><th>name<\/th><th>salary<\/th><th>quartile<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>\u5f20\u4e09<\/td><td>9000<\/td><td>1<\/td><\/tr><tr><td>2<\/td><td>\u674e\u56db<\/td><td>8500<\/td><td>1<\/td><\/tr><tr><td>3<\/td><td>\u738b\u4e94<\/td><td>8500<\/td><td>2<\/td><\/tr><tr><td>4<\/td><td>\u8d75\u516d<\/td><td>7000<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>LEAD()<\/strong> \u548c <strong>LAG()<\/strong> &#8211; \u83b7\u53d6\u5f53\u524d\u884c\u7684\u524d\u540e\u884c\u6570\u636e<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>LEAD()<\/code><\/strong> \u83b7\u53d6\u5f53\u524d\u884c\u4e4b\u540e\u7684\u4e00\u884c\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong><code>LAG()<\/code><\/strong> \u83b7\u53d6\u5f53\u524d\u884c\u4e4b\u524d\u7684\u4e00\u884c\u6570\u636e\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n    id, \n    name, \n    salary, \n    LAG(salary, 1) OVER (ORDER BY salary DESC) AS prev_salary, \n    LEAD(salary, 1) OVER (ORDER BY salary DESC) AS next_salary\nFROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u91ca<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>LAG(salary, 1)<\/code> \u83b7\u53d6\u5f53\u524d\u5458\u5de5\u85aa\u8d44\u7684\u524d\u4e00\u4e2a\u5458\u5de5\u85aa\u8d44\uff08\u5982\u679c\u6709\u7684\u8bdd\uff09\u3002<\/li>\n\n\n\n<li><code>LEAD(salary, 1)<\/code> \u83b7\u53d6\u5f53\u524d\u5458\u5de5\u85aa\u8d44\u7684\u4e0b\u4e00\u4e2a\u5458\u5de5\u85aa\u8d44\uff08\u5982\u679c\u6709\u7684\u8bdd\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ed3\u679c\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>id<\/th><th>name<\/th><th>salary<\/th><th>prev_salary<\/th><th>next_salary<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>\u5f20\u4e09<\/td><td>9000<\/td><td>NULL<\/td><td>8500<\/td><\/tr><tr><td>2<\/td><td>\u674e\u56db<\/td><td>8500<\/td><td>9000<\/td><td>8500<\/td><\/tr><tr><td>3<\/td><td>\u738b\u4e94<\/td><td>8500<\/td><td>8500<\/td><td>7000<\/td><\/tr><tr><td>4<\/td><td>\u8d75\u516d<\/td><td>7000<\/td><td>8500<\/td><td>NULL<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>SUM()<\/strong> \u548c <strong>AVG()<\/strong> &#8211; \u6309\u7ec4\u8ba1\u7b97\u603b\u548c\u6216\u5e73\u5747\u503c<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u5e38\u7528\u7684\u805a\u5408\u51fd\u6570\u53ef\u4ee5\u914d\u5408 <code>PARTITION BY<\/code> \u7528\u4e8e\u6bcf\u4e2a\u5206\u7ec4\u5185\u7684\u8ba1\u7b97\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n    id, \n    name, \n    salary, \n    SUM(salary) OVER (PARTITION BY department) AS dept_salary_sum,\n    AVG(salary) OVER (PARTITION BY department) AS dept_avg_salary\nFROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u91ca<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SUM(salary) OVER (PARTITION BY department)<\/code> \u4f1a\u6309\u90e8\u95e8\uff08<code>department<\/code>\uff09\u8ba1\u7b97\u6bcf\u4e2a\u90e8\u95e8\u7684\u603b\u85aa\u8d44\u3002<\/li>\n\n\n\n<li><code>AVG(salary) OVER (PARTITION BY department)<\/code> \u4f1a\u6309\u90e8\u95e8\u8ba1\u7b97\u6bcf\u4e2a\u90e8\u95e8\u7684\u5e73\u5747\u85aa\u8d44\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ed3\u679c\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>id<\/th><th>name<\/th><th>department<\/th><th>salary<\/th><th>dept_salary_sum<\/th><th>dept_avg_salary<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>\u5f20\u4e09<\/td><td>IT<\/td><td>9000<\/td><td>17000<\/td><td>8500<\/td><\/tr><tr><td>2<\/td><td>\u674e\u56db<\/td><td>IT<\/td><td>8000<\/td><td>17000<\/td><td>8500<\/td><\/tr><tr><td>3<\/td><td>\u738b\u4e94<\/td><td>HR<\/td><td>7000<\/td><td>7000<\/td><td>7000<\/td><\/tr><tr><td>4<\/td><td>\u8d75\u516d<\/td><td>HR<\/td><td>7000<\/td><td>7000<\/td><td>7000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. \u603b\u7ed3\u548c\u5e94\u7528\u573a\u666f<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6392\u540d\u8ba1\u7b97<\/strong>\uff1a<code>ROW_NUMBER()<\/code>, <code>RANK()<\/code>, <code>DENSE_RANK()<\/code> \u5e38\u7528\u4e8e\u8ba1\u7b97\u6392\u540d\uff0c\u5904\u7406\u4f8b\u5982\u9500\u552e\u3001\u7ade\u8d5b\u7b49\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong>\u524d\u540e\u884c\u6570\u636e\u6bd4\u8f83<\/strong>\uff1a<code>LAG()<\/code> \u548c <code>LEAD()<\/code> \u7528\u4e8e\u6bd4\u8f83\u5f53\u524d\u884c\u548c\u76f8\u90bb\u884c\u7684\u503c\uff0c\u9002\u7528\u4e8e\u8ba1\u7b97\u8d8b\u52bf\u3001\u5dee\u5f02\u7b49\u3002<\/li>\n\n\n\n<li><strong>\u5206\u7ec4\u6c47\u603b<\/strong>\uff1a<code>SUM()<\/code>, <code>AVG()<\/code>, <code>MIN()<\/code>, <code>MAX()<\/code> \u53ef\u4ee5\u6309\u5206\u7ec4\u8ba1\u7b97\u603b\u548c\u3001\u5e73\u5747\u503c\u3001\u6700\u5c0f\u503c\u3001\u6700\u5927\u503c\u7b49\uff0c\u9002\u7528\u4e8e\u8d22\u52a1\u7edf\u8ba1\u3001\u4e1a\u7ee9\u5206\u6790\u7b49\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u8fd9\u4e9b\u7a97\u53e3\u51fd\u6570\uff0c\u4f60\u80fd\u591f\u5728 SQL \u67e5\u8be2\u4e2d\u4e0d\u4e22\u5931\u884c\u6570\u636e\u7684\u524d\u63d0\u4e0b\u8fdb\u884c\u5f3a\u5927\u7684\u8ba1\u7b97\u5206\u6790\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4e86\u5e2e\u52a9\u4f60\u66f4\u8be6\u7ec6\u3001\u6e05\u6670\u5730\u7406\u89e3 SQL \u7a97\u53e3\u51fd\u6570\uff0c\u672c\u6587\u4ece\u96f6\u5f00\u59cb\u8be6\u7ec6\u89e3\u91ca\uff0c\u5e76\u901a\u8fc7\u9010\u6b65\u793a\u4f8b\u6765\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u3002\u7a97 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-611","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=611"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/611\/revisions"}],"predecessor-version":[{"id":612,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/611\/revisions\/612"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}