{"id":16372,"date":"2024-11-15T02:04:07","date_gmt":"2024-11-14T22:34:07","guid":{"rendered":"https:\/\/www.itpiran.net\/blog\/?p=16372"},"modified":"2024-11-15T02:04:07","modified_gmt":"2024-11-14T22:34:07","slug":"how-to-use-functions-in-sqlusing-date-and-time-functions","status":"publish","type":"post","link":"https:\/\/www.itpiran.net\/blog\/zh\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/","title":{"rendered":"\u5982\u4f55\u5728 SQL \u4e2d\u4f7f\u7528\u51fd\u6570"},"content":{"rendered":"<h2 id=\"%d9%85%d9%82%d8%af%d9%85%d9%87\">\u4ecb\u7ecd<\/h2>\n<p>\u5728\u4f7f\u7528\u5173\u7cfb\u578b\u6570\u636e\u5e93\u548c\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00 (SQL) \u65f6\uff0c\u60a8\u53ef\u4ee5\u4ece\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u4e2d\u5b58\u50a8\u3001\u7ba1\u7406\u548c\u68c0\u7d22\u6570\u636e\u3002SQL \u53ef\u4ee5\u5b8c\u6574\u5730\u68c0\u7d22\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u3002.<\/p>\n<p>SQL \u8fd8\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570\u6267\u884c\u8ba1\u7b97\u548c\u5904\u7406\u6570\u636e\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u68c0\u7d22\u56db\u820d\u4e94\u5165\u5230\u6700\u63a5\u8fd1\u7684\u7f8e\u5143\u7684\u4ea7\u54c1\u4ef7\u683c\u3001\u8ba1\u7b97\u4ea7\u54c1\u5e73\u5747\u8d2d\u4e70\u6570\u91cf\uff0c\u6216\u786e\u5b9a\u8d2d\u4e70\u5546\u54c1\u7684\u4fdd\u4fee\u671f\u5269\u4f59\u5929\u6570\u3002.<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u60a8\u5c06\u4f7f\u7528\u5404\u79cd SQL \u51fd\u6570\u6765\u6267\u884c\u6570\u5b66\u8ba1\u7b97\u3001\u64cd\u4f5c\u5b57\u7b26\u4e32\u548c\u65e5\u671f\uff0c\u4ee5\u53ca\u4f7f\u7528\u805a\u5408\u51fd\u6570\u8ba1\u7b97\u6c47\u603b\u4fe1\u606f\u3002.<\/p>\n<h5 id=\"%d9%be%db%8c%d8%b4%d9%86%db%8c%d8%a7%d8%b2%d9%87%d8%a7\">\u5148\u51b3\u6761\u4ef6<\/h5>\n<p>\u8981\u9075\u5faa\u672c\u6307\u5357\uff0c\u60a8\u9700\u8981\u4e00\u53f0\u8fd0\u884c\u57fa\u4e8e SQL \u7684\u5173\u7cfb\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf (RDBMS) \u7684\u8ba1\u7b97\u673a\u3002\u672c\u6307\u5357\u4e2d\u7684\u8bf4\u660e\u548c\u793a\u4f8b\u5df2\u5728\u4ee5\u4e0b\u73af\u5883\u4e2d\u9a8c\u8bc1\uff1a<\/p>\n<ul>\n<li>\u4e00\u53f0\u8fd0\u884c Ubuntu 20.04 \u7684\u670d\u52a1\u5668\uff0c\u5177\u6709\u5177\u6709\u7ba1\u7406\u6743\u9650\u7684\u975e root \u7528\u6237\uff0c\u5e76\u4e14\u914d\u7f6e\u4e86 UFW \u9632\u706b\u5899\uff0c\u5982 Ubuntu 20.04 \u521d\u59cb\u670d\u52a1\u5668\u8bbe\u7f6e\u6307\u5357\u4e2d\u6240\u8ff0\u3002.<\/li>\n<li>MySQL \u5df2\u6309\u7167\u201c\u5982\u4f55\u5728 Ubuntu 20.04 \u4e0a\u5b89\u88c5 MySQL\u201d\u6307\u5357\u4e2d\u7684\u8bf4\u660e\uff0c\u5728\u670d\u52a1\u5668\u4e0a\u5b89\u88c5\u5e76\u8fdb\u884c\u4e86\u5b89\u5168\u914d\u7f6e\u3002\u672c\u6307\u5357\u5047\u8bbe\u4f7f\u7528\u6309\u7167\u6b65\u9aa4 3 \u4e2d\u6240\u8ff0\u8fc7\u7a0b\u521b\u5efa\u7684\u975e root \u7528\u6237\u3002.<\/li>\n<li>\u672c\u6587\u5c06\u5bf9\u5982\u4f55\u6267\u884c SELECT \u67e5\u8be2\u4ee5\u4ece\u6570\u636e\u5e93\u4e2d\u9009\u62e9\u6570\u636e\u8fdb\u884c\u57fa\u672c\u4ecb\u7ecd\uff0c\u5982\u201c\u5982\u4f55\u5728 SQL \u4e2d\u4ece\u8868\u4e2d\u9009\u62e9\u884c\u201d\u6307\u5357\u4e2d\u6240\u8ff0\u3002.<\/li>\n<\/ul>\n<p><span style=\"color: #ff0000;\">\u6ce8\u610f\uff1a\u8bb8\u591a\u5173\u7cfb\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf (RDBMS) \u4f7f\u7528\u5404\u81ea\u7684 SQL \u5b9e\u73b0\u3002\u867d\u7136\u672c\u6559\u7a0b\u4e2d\u63cf\u8ff0\u7684\u547d\u4ee4\u5728\u5927\u591a\u6570 RDBMS \u4e2d\u90fd\u80fd\u8fd0\u884c\uff0c\u4f46\u6807\u51c6 SQL \u8bed\u6cd5\u4ec5\u5b9a\u4e49\u4e86\u6709\u9650\u6570\u91cf\u7684\u51fd\u6570\u3002\u6b64\u5916\uff0c\u4e0d\u540c\u6570\u636e\u5e93\u5f15\u64ce\u5bf9\u6807\u51c6\u8bed\u6cd5\u7684\u652f\u6301\u4e5f\u5404\u4e0d\u76f8\u540c\u3002\u5982\u679c\u60a8\u5728 MySQL \u4ee5\u5916\u7684\u7cfb\u7edf\u4e0a\u6d4b\u8bd5\u8fd9\u4e9b\u547d\u4ee4\uff0c\u5219\u5177\u4f53\u7684\u8bed\u6cd5\u6216\u8f93\u51fa\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002.<\/span><\/p>\n<p>\u60a8\u8fd8\u9700\u8981\u4e00\u4e2a\u6570\u636e\u5e93\uff0c\u5176\u4e2d\u5305\u542b\u52a0\u8f7d\u4e86\u793a\u4f8b\u6570\u636e\u7684\u8868\uff0c\u4ee5\u4fbf\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u3002\u6211\u4eec\u5efa\u8bae\u60a8\u67e5\u770b\u201c\u8fde\u63a5\u5230 MySQL \u5e76\u8bbe\u7f6e\u793a\u4f8b\u6570\u636e\u5e93\u201d\u90e8\u5206\uff0c\u4e86\u89e3\u6709\u5173\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\u4ee5\u53ca\u521b\u5efa\u672c\u6307\u5357\u793a\u4f8b\u4e2d\u4f7f\u7528\u7684\u6d4b\u8bd5\u6570\u636e\u5e93\u7684\u8be6\u7ec6\u4fe1\u606f\u3002.<\/p>\n<h3 id=\"%d8%a7%d8%aa%d8%b5%d8%a7%d9%84-%d8%a8%d9%87-mysql-%d9%88-%d8%b1%d8%a7%d9%87%d8%a7%d9%86%d8%af%d8%a7%d8%b2%db%8c-%db%8c%da%a9-%d9%be%d8%a7%db%8c%da%af%d8%a7%d9%87-%d8%af%d8%a7%d8%af%d9%87\">\u8fde\u63a5\u5230 MySQL \u5e76\u8bbe\u7f6e\u793a\u4f8b\u6570\u636e\u5e93<\/h3>\n<p>\u5728\u672c\u8282\u4e2d\uff0c\u60a8\u5c06\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\u5e76\u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u6570\u636e\u5e93\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u6309\u7167\u672c\u6307\u5357\u4e2d\u7684\u793a\u4f8b\u8fdb\u884c\u64cd\u4f5c\u3002.<\/p>\n<p>\u5982\u679c\u60a8\u7684 SQL \u6570\u636e\u5e93\u7cfb\u7edf\u8fd0\u884c\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\uff0c\u8bf7\u901a\u8fc7 SSH \u767b\u5f55\u5230\u60a8\u7684\u670d\u52a1\u5668\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>ssh sammy@your_server_ip<\/code><\/pre>\n<\/div>\n<p>\u7136\u540e\u6253\u5f00 MySQL \u670d\u52a1\u5668\u73af\u5883\uff0c\u800c\u4e0d\u662f <code>\u8428\u7c73<\/code> \u8bf7\u8f93\u5165\u60a8\u7684 MySQL \u7528\u6237\u540d\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>mysql -u sammy -p<\/code><\/pre>\n<\/div>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201c\u4e66\u5e97\u201d\u7684\u6570\u636e\u5e93\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>CREATE DATABASE bookstore;<\/code><\/pre>\n<\/div>\n<p>\u5982\u679c\u6570\u636e\u5e93\u521b\u5efa\u6210\u529f\uff0c\u60a8\u5c06\u6536\u5230\u7c7b\u4f3c\u4ee5\u4e0b\u5185\u5bb9\u7684\u8f93\u51fa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nQuery OK, 1 row affected (0.01 sec)<\/code><\/pre>\n<\/div>\n<p>\u8981\u9009\u62e9\u4e66\u5e97\u6570\u636e\u5e93\uff0c\u8bf7\u8fd0\u884c USE \u547d\u4ee4\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>USE bookstore;<\/code><\/pre>\n<\/div>\n<p>\u60a8\u5c06\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nDatabase changed<\/code><\/pre>\n<\/div>\n<p>\u9009\u62e9\u6570\u636e\u5e93\u540e\uff0c\u5373\u53ef\u5728\u5176\u4e2d\u521b\u5efa\u793a\u4f8b\u8868\u3002\u5728\u672c\u6307\u5357\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u4e00\u4e2a\u865a\u6784\u7684\u56fe\u4e66\u9986\uff0c\u8be5\u56fe\u4e66\u9986\u51fa\u552e\u4e0d\u540c\u4f5c\u8005\u7684\u5404\u79cd\u4e66\u7c4d\u3002.<\/p>\n<p>\u5e93\u5b58\u8868\u5305\u542b\u4e66\u5e97\u73b0\u6709\u4e66\u7c4d\u7684\u4fe1\u606f\u3002\u5b83\u5305\u542b\u4ee5\u4e0b\u5217\uff1a<\/p>\n<ul>\n<li>book_id\uff1a\u6b64\u5217\u5305\u542b\u6bcf\u672c\u4e66\u7684 ID\uff0c\u6570\u636e\u7c7b\u578b\u4e3a int\u3002\u6b64\u5217\u5c06\u6210\u4e3a\u8868\u7684\u4e3b\u952e\uff0c\u6bcf\u4e2a\u503c\u90fd\u6210\u4e3a\u5bf9\u5e94\u884c\u7684\u552f\u4e00\u6807\u8bc6\u7b26\u3002.<\/li>\n<li>\u4f5c\u8005\uff1a\u672c\u5217\u5305\u542b\u4e66\u7c4d\u4f5c\u8005\u7684\u59d3\u540d\uff0c\u4f7f\u7528 varchar \u6570\u636e\u7c7b\u578b\u8868\u793a\uff0c\u6700\u591a 50 \u4e2a\u5b57\u7b26\u3002.<\/li>\n<li>\u6807\u9898\uff1a\u6b64\u5217\u5305\u542b\u6240\u8d2d\u4e66\u7c4d\u7684\u6807\u9898\uff0c\u4f7f\u7528 varchar \u6570\u636e\u7c7b\u578b\u8868\u793a\uff0c\u6700\u591a 200 \u4e2a\u5b57\u7b26\u3002.<\/li>\n<li>introduction_date\uff1a\u6b64\u5217\u4f7f\u7528\u65e5\u671f\u6570\u636e\u7c7b\u578b\u8bb0\u5f55\u4e66\u5e97\u63a8\u51fa\u6bcf\u672c\u4e66\u7684\u65e5\u671f\u3002.<\/li>\n<li>\u5e93\u5b58\uff1a\u6b64\u5217\u4ee5\u6574\u6570\u6570\u636e\u7c7b\u578b\u4fdd\u5b58\u4e66\u5e97\u5e93\u5b58\u4e66\u7c4d\u7684\u6570\u91cf\u3002.<\/li>\n<li>\u4ef7\u683c\uff1a\u6b64\u5217\u5b58\u50a8\u4e66\u7c4d\u7684\u96f6\u552e\u4ef7\u683c\uff0c\u91c7\u7528\u5341\u8fdb\u5236\u6570\u636e\u7c7b\u578b\uff0c\u5c0f\u6570\u70b9\u524d\u6700\u591a 5 \u4e2a\u503c\uff0c\u5c0f\u6570\u70b9\u540e\u6700\u591a 2 \u4e2a\u503c\u3002.<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u793a\u4f8b\u8868\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>CREATE TABLE inventory (\r\nbook_id int,\r\nauthor varchar(50),\r\ntitle varchar(200),\r\nintroduction_date date,\r\nstock int,\r\nprice decimal(5, 2),\r\nPRIMARY KEY (book_id)\r\n);<\/code><\/pre>\n<\/div>\n<p>\u5982\u679c\u6253\u5370\u51fa\u4ee5\u4e0b\u8f93\u51fa\uff0c\u5219\u8868\u793a\u8868\u683c\u5df2\u521b\u5efa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nQuery OK, 0 rows affected (0.00 sec)<\/code><\/pre>\n<\/div>\n<p>\u7136\u540e\uff0c\u901a\u8fc7\u6267\u884c\u4ee5\u4e0b INSERT INTO \u64cd\u4f5c\uff0c\u5c06\u4e00\u4e9b\u793a\u4f8b\u6570\u636e\u52a0\u8f7d\u5230 purchases \u8868\u4e2d\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>INSERT INTO inventory\r\nVALUES\r\n(1, 'Oscar Wilde', 'The Picture of Dorian Gray', '2022-10-01', 4, 20.83),\r\n(2, 'Jane Austen', 'Pride and Prejudice', '2022-10-04', 12, 42.13),\r\n(3, 'Herbert George Wells', 'The Time Machine', '2022-09-23', 7, 21.99),\r\n(4, 'Mary Shelley', 'Frankenstein', '2022-07-23', 9, 17.43),\r\n(5, 'Mark Twain', 'The Adventures of Huckleberry Finn', '2022-10-01', 14, 23.15);<\/code><\/pre>\n<\/div>\n<p>INSERT INTO \u64cd\u4f5c\u5c06\u4e94\u672c\u5177\u6709\u6307\u5b9a\u503c\u7684\u4e66\u7c4d\u6dfb\u52a0\u5230\u5e93\u5b58\u8868\u4e2d\u3002\u4ee5\u4e0b\u8f93\u51fa\u663e\u793a\u6240\u6709\u4e94\u884c\u6570\u636e\u5747\u5df2\u6dfb\u52a0\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nQuery OK, 5 rows affected (0.00 sec)\r\nRecords: 5 Duplicates: 0 Warnings: 0\r\n<\/code><\/pre>\n<\/div>\n<p>\u81f3\u6b64\uff0c\u60a8\u5c31\u53ef\u4ee5\u7ee7\u7eed\u9605\u8bfb\u672c\u6307\u5357\u7684\u5176\u4f59\u90e8\u5206\uff0c\u5e76\u5f00\u59cb\u5728 SQL \u4e2d\u4f7f\u7528\u51fd\u6570\u4e86\u3002.<\/p>\n<h2 id=\"%d8%af%d8%b1%da%a9-%d8%aa%d9%88%d8%a7%d8%a8%d8%b9-sql\">\u4e86\u89e3 SQL \u51fd\u6570<\/h2>\n<p>\u51fd\u6570\u662f\u547d\u540d\u8868\u8fbe\u5f0f\uff0c\u5b83\u63a5\u53d7\u4e00\u4e2a\u6216\u591a\u4e2a\u503c\uff0c\u5bf9\u6570\u636e\u6267\u884c\u8ba1\u7b97\u6216\u8f6c\u6362\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u503c\u4f5c\u4e3a\u7ed3\u679c\u3002\u60a8\u53ef\u4ee5\u5c06 SQL \u51fd\u6570\u7406\u89e3\u4e3a\u7c7b\u4f3c\u4e8e\u6570\u5b66\u51fd\u6570\u3002\u4f8b\u5982\uff0clog(x) \u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u503c x\uff0c\u5e76\u8fd4\u56de x \u7684\u5bf9\u6570\u3002.<\/p>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u68c0\u7d22\u6240\u6709\u4e66\u7c4d\u540d\u79f0\u53ca\u5176\u4ef7\u683c\uff0c\u5e76\u6309\u4ef7\u683c\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\uff0c\u60a8\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT title, price, introduction_date FROM inventory ORDER BY price DESC;<\/code><\/pre>\n<\/div>\n<p>\u60a8\u5c06\u5f97\u5230\u7c7b\u4f3c\u5982\u4e0b\u7684\u8f93\u51fa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\n+------------------------------------+-------+-------------------+\r\n| title | price | introduction_date |\r\n+------------------------------------+-------+-------------------+\r\n| Pride and Prejudice | 42.13 | 2022-10-04 |\r\n| The Adventures of Huckleberry Finn | 23.15 | 2022-10-01 |\r\n| The Time Machine | 21.99 | 2022-09-23 |\r\n| The Picture of Dorian Gray | 20.83 | 2022-10-01 |\r\n| Frankenstein | 17.43 | 2022-07-23 |\r\n+------------------------------------+-------+-------------------+\r\n5 rows in set (0.000 sec)<\/code><\/pre>\n<\/div>\n<p>\u5728\u8fd9\u4e2a\u547d\u4ee4\u4e2d\uff0c <code>\u6807\u9898<\/code>\uff0c <code>\u4ef7\u683c<\/code> \u548c <code>\u4ecb\u7ecd\u65e5\u671f<\/code> \u662f\u5217\u540d\uff0c\u5728\u8f93\u51fa\u4e2d\uff0c\u6570\u636e\u5e93\u663e\u793a\u4e86\u4ece\u8fd9\u4e9b\u5217\u4e2d\u68c0\u7d22\u5230\u7684\u6bcf\u672c\u4e66\u7684\u5b8c\u6574\u503c\uff1a\u4e66\u7684\u5b8c\u6574\u6807\u9898\u3001\u4ef7\u683c\u548c\u4e66\u7c4d\u5230\u8fbe\u56fe\u4e66\u9986\u7684\u65e5\u671f\u3002.<\/p>\n<p>\u4f46\u662f\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5bf9\u6570\u636e\u5e93\u8fdb\u884c\u4e00\u4e9b\u5904\u7406\u6216\u64cd\u4f5c\u540e\u518d\u68c0\u7d22\u503c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u60f3\u8981\u83b7\u53d6\u56db\u820d\u4e94\u5165\u5230\u6700\u63a5\u8fd1\u7684\u7f8e\u5143\u7684\u4e66\u7c4d\u4ef7\u683c\u3001\u5168\u5927\u5199\u7684\u4e66\u7c4d\u6807\u9898\uff0c\u6216\u8005\u4e0d\u5305\u542b\u6708\u4efd\u6216\u65e5\u671f\u7684\u51fa\u7248\u5e74\u4efd\u3002\u8fd9\u65f6\u5c31\u9700\u8981\u4f7f\u7528\u51fd\u6570\u4e86\u3002.<\/p>\n<p>SQL \u51fd\u6570\u53ef\u4ee5\u6839\u636e\u5176\u64cd\u4f5c\u7684\u6570\u636e\u7c7b\u578b\u5927\u81f4\u5206\u4e3a\u51e0\u7c7b\u3002\u4ee5\u4e0b\u662f\u6700\u5e38\u7528\u7684\u51fd\u6570\uff1a<\/p>\n<ul>\n<li>\u6570\u5b66\u51fd\u6570\uff1a\u5bf9\u6570\u503c\u8fdb\u884c\u8fd0\u7b97\u5e76\u6267\u884c\u8ba1\u7b97\u7684\u51fd\u6570\uff0c\u4f8b\u5982\u56db\u820d\u4e94\u5165\u3001\u5bf9\u6570\u3001\u5e73\u65b9\u6839\u6216\u5e42\u8fd0\u7b97\u3002.<\/li>\n<li>\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\uff1a\u5bf9\u5b57\u7b26\u4e32\u548c\u6587\u672c\u5b57\u6bb5\u8fdb\u884c\u64cd\u4f5c\u7684\u51fd\u6570\uff0c\u6267\u884c\u6587\u672c\u8f6c\u6362\uff0c\u4f8b\u5982\u5c06\u6587\u672c\u8f6c\u6362\u4e3a\u5927\u5199\u3001\u622a\u65ad\u6216\u66ff\u6362\u503c\u4e2d\u7684\u5355\u8bcd\u3002.<\/li>\n<li>\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\uff1a\u5bf9\u65e5\u671f\u5b57\u6bb5\u8fdb\u884c\u64cd\u4f5c\u7684\u51fd\u6570\u3002\u8fd9\u4e9b\u51fd\u6570\u6267\u884c\u8ba1\u7b97\u548c\u8f6c\u6362\uff0c\u4f8b\u5982\u5411\u7ed9\u5b9a\u65e5\u671f\u52a0\u4e0a\u5929\u6570\u6216\u4ece\u5b8c\u6574\u65e5\u671f\u4e2d\u51cf\u53bb\u4e00\u5e74\u3002.<\/li>\n<li>\u805a\u5408\u51fd\u6570\uff1a\u4e00\u79cd\u7279\u6b8a\u7684\u6570\u5b66\u51fd\u6570\uff0c\u5b83\u5bf9\u4ece\u591a\u884c\u83b7\u5f97\u7684\u503c\u8fdb\u884c\u64cd\u4f5c\uff0c\u4f8b\u5982\u8ba1\u7b97\u6240\u6709\u884c\u7684\u5e73\u5747\u4ef7\u683c\u3002.<\/li>\n<\/ul>\n<p><span style=\"color: #ff0000;\">\u6ce8\u610f\uff1a\u5927\u591a\u6570\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff08\u5305\u62ec MySQL\uff09\u90fd\u4f1a\u6269\u5c55 SQL \u6807\u51c6\u5b9a\u4e49\u7684\u6807\u51c6\u51fd\u6570\u96c6\uff0c\u6dfb\u52a0\u4e00\u4e9b\u7279\u5b9a\u4e8e\u6570\u636e\u5e93\u5f15\u64ce\u7684\u64cd\u4f5c\u3002\u8bb8\u591a\u6807\u51c6 SQL \u51fd\u6570\u96c6\u4e4b\u5916\u7684\u51fd\u6570\u5728\u8bb8\u591a\u6570\u636e\u5e93\u4e2d\u90fd\u80fd\u4ee5\u7c7b\u4f3c\u7684\u65b9\u5f0f\u8fd0\u884c\uff0c\u800c\u53e6\u4e00\u4e9b\u51fd\u6570\u5219\u7279\u5b9a\u4e8e\u67d0\u4e2a\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf (RDBMS) \u53ca\u5176\u72ec\u7279\u529f\u80fd\u3002\u60a8\u53ef\u4ee5\u53c2\u8003\u6240\u9009\u6570\u636e\u5e93\u7684\u6587\u6863\uff0c\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u8be5\u6570\u636e\u5e93\u63d0\u4f9b\u7684\u51fd\u6570\u7684\u4fe1\u606f\u3002\u4ee5 MySQL \u4e3a\u4f8b\uff0c\u60a8\u53ef\u4ee5\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u5185\u7f6e\u51fd\u6570\u548c\u8fd0\u7b97\u7b26\u53c2\u8003\u7684\u4fe1\u606f\u3002.<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u4f7f\u7528\u540d\u4e3a EXAMPLE \u7684\u865a\u6784\u51fd\u6570\uff08\u8be5\u51fd\u6570\u5e76\u4e0d\u5b58\u5728\uff09\u6765\u4fee\u6539\u4e66\u5e97\u5e93\u5b58\u6570\u636e\u5e93\u4e2d\u4ef7\u683c\u503c\u7ed3\u679c\u7684\u4e00\u822c\u8bed\u6cd5\uff0c\u8be5\u51fd\u6570\u901a\u8fc7 SELECT \u67e5\u8be2\u5b9e\u73b0\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT EXAMPLE(price) AS new_price FROM inventory;\r\n<\/code><\/pre>\n<\/div>\n<p>\u51fd\u6570 (EXAMPLE) \u63a5\u53d7\u4e00\u4e2a\u7528\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u53c2\u6570\uff0c\u53c2\u6570\u4e3a\u5217\u540d (price)\u3002\u67e5\u8be2\u7684\u8fd9\u4e00\u90e8\u5206\u6307\u793a\u6570\u636e\u5e93\u5bf9\u5217\u4e2d\u7684 price \u503c\u8fd0\u884c EXAMPLE \u51fd\u6570\uff0c\u5e76\u8fd4\u56de\u8fd0\u7b97\u7ed3\u679c\u3002AS new_price \u6307\u793a\u6570\u636e\u5e93\u4e3a\u67e5\u8be2\u8fc7\u7a0b\u4e2d\u8ba1\u7b97\u51fa\u7684\u503c\u5206\u914d\u4e00\u4e2a\u4e34\u65f6\u540d\u79f0 (new_price)\u3002\u901a\u8fc7\u8fd9\u4e2a\u4e34\u65f6\u540d\u79f0\uff0c\u60a8\u53ef\u4ee5\u5728\u8f93\u51fa\u4e2d\u8bc6\u522b\u51fd\u6570\u7684\u8fd0\u7b97\u7ed3\u679c\uff0c\u5e76\u4f7f\u7528 WHERE \u548c ORDER BY \u5b50\u53e5\u5f15\u7528\u8fd9\u4e9b\u8ba1\u7b97\u503c\u3002.<\/p>\n<p>\u5728\u63a5\u4e0b\u6765\u7684\u90e8\u5206\u4e2d\uff0c\u4f60\u5c06\u4f7f\u7528\u6570\u5b66\u51fd\u6570\u8fdb\u884c\u5e38\u89c1\u8ba1\u7b97\u3002.<\/p>\n<h2 id=\"%d8%a7%d8%b3%d8%aa%d9%81%d8%a7%d8%af%d9%87-%d8%a7%d8%b2-%d8%aa%d9%88%d8%a7%d8%a8%d8%b9-%d8%b1%db%8c%d8%a7%d8%b6%db%8c\">\u5229\u7528\u6570\u5b66\u51fd\u6570<\/h2>\n<p>\u6570\u5b66\u51fd\u6570\u5904\u7406\u7684\u662f\u6570\u503c\uff0c\u4f8b\u5982\u793a\u4f8b\u6570\u636e\u5e93\u4e2d\u4e66\u7c4d\u7684\u4ef7\u683c\u6216\u5e93\u5b58\u6570\u91cf\u3002\u5b83\u4eec\u53ef\u7528\u4e8e\u5728\u6570\u636e\u5e93\u4e2d\u6267\u884c\u8ba1\u7b97\uff0c\u4ece\u800c\u6839\u636e\u60a8\u7684\u9700\u6c42\u5b9a\u5236\u7ed3\u679c\u3002.<\/p>\n<p>\u5728 SQL \u4e2d\uff0c\u56db\u820d\u4e94\u5165\u662f\u6570\u5b66\u51fd\u6570\u6700\u5e38\u89c1\u7684\u7528\u9014\u4e4b\u4e00\u3002\u5047\u8bbe\u4f60\u9700\u8981\u68c0\u7d22\u6240\u6709\u4e66\u7c4d\u7684\u4ef7\u683c\uff0c\u4f46\u4f60\u53ea\u60f3\u83b7\u53d6\u56db\u820d\u4e94\u5165\u5230\u6700\u63a5\u8fd1\u7684\u6574\u6570\u7f8e\u5143\u7684\u4ef7\u683c\u3002\u4e3a\u6b64\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 `for` \u51fd\u6570\u3002 <code>\u5706\u5f62\u7684<\/code> \u4f7f\u7528\u6267\u884c\u820d\u5165\u64cd\u4f5c\u7684\u5de5\u5177\u3002.<\/p>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT title, price, ROUND(price) AS rounded_price FROM inventory;\r\n<\/code><\/pre>\n<\/div>\n<p>\u60a8\u5c06\u770b\u5230\u7c7b\u4f3c\u4ee5\u4e0b\u5185\u5bb9\u7684\u8f93\u51fa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\n+------------------------------------+-------+---------------+\r\n| title | price | rounded_price |\r\n+------------------------------------+-------+---------------+\r\n| The Picture of Dorian Gray | 20.83 | 21 |\r\n| Pride and Prejudice | 42.13 | 42 |\r\n| The Time Machine | 21.99 | 22 |\r\n| Frankenstein | 17.43 | 17 |\r\n| The Adventures of Huckleberry Finn | 23.15 | 23 |\r\n+------------------------------------+-------+---------------+\r\n5 rows in set (0.000 sec)<\/code><\/pre>\n<\/div>\n<p>\u4e0a\u8ff0\u547d\u4ee4\u8fd4\u56de\u5404\u5217\u7684\u503c\u3002 <code>\u6807\u9898<\/code> \u548c <code>\u4ef7\u683c<\/code> \u4e34\u65f6\u67f1 <code>\u56db\u820d\u4e94\u5165\u4ef7\u683c<\/code> \u8fd9\u662f\u7531\u8be5\u51fd\u6570\u4ea7\u751f\u7684 <code>ROUND(\u4ef7\u683c)<\/code> \u6b64\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u5373\u5217\u540d\uff08\u6b64\u5904\u4e3a\uff1a <code>\u4ef7\u683c<\/code>) \u5e76\u5c06\u8868\u683c\u4e2d\u8be5\u5217\u7684\u503c\u56db\u820d\u4e94\u5165\u5230\u6700\u63a5\u8fd1\u7684\u6574\u6570\u3002.<\/p>\n<p>ROUND \u51fd\u6570\u8fd8\u53ef\u4ee5\u63a5\u53d7\u5176\u4ed6\u53c2\u6570\uff0c\u7528\u4e8e\u6307\u5b9a\u820d\u5165\u7684\u5c0f\u6570\u4f4d\u6570\uff0c\u4ee5\u53ca\u4f7f\u7528\u7b97\u672f\u8fd0\u7b97\u4ee3\u66ff\u5217\u540d\u3002\u4f8b\u5982\uff0c\u8fd0\u884c\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT title, price, ROUND(price * stock, 1) AS stock_price FROM inventory;\r\n<\/code><\/pre>\n<\/div>\n<p>\u60a8\u5c06\u5f97\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\n+------------------------------------+-------+-------+-------------+\r\n| title | stock | price | stock_price |\r\n+------------------------------------+-------+-------+-------------+\r\n| The Picture of Dorian Gray | 4 | 20.83 | 83.3 |\r\n| Pride and Prejudice | 12 | 42.13 | 505.6 |\r\n| The Time Machine | 7 | 21.99 | 153.9 |\r\n| Frankenstein | 9 | 17.43 | 156.9 |\r\n| The Adventures of Huckleberry Finn | 14 | 23.15 | 324.1 |\r\n+------------------------------------+-------+-------+-------------+\r\n5 rows in set (0.000 sec)<\/code><\/pre>\n<\/div>\n<p>\u6267\u884c <code>ROUND(\u4ef7\u683c * \u5e93\u5b58, 1)<\/code> \u5b83\u9996\u5148\u5c06\u5355\u672c\u4e66\u7684\u4ef7\u683c\u4e58\u4ee5\u73b0\u6709\u4e66\u7c4d\u7684\u6570\u91cf\uff0c\u7136\u540e\u5c06\u7ed3\u679c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e00\u4f4d\u3002\u7ed3\u679c\u5c06\u663e\u793a\u5728\u4e34\u65f6\u5217 Stock_Price \u4e2d\u3002.<\/p>\n<p>MySQL \u5185\u7f6e\u7684\u5176\u4ed6\u6570\u5b66\u51fd\u6570\u5305\u62ec\u4e09\u89d2\u51fd\u6570\u3001\u5e73\u65b9\u6839\u3001\u5e42\u8fd0\u7b97\u3001\u5bf9\u6570\u548c\u6307\u6570\u51fd\u6570\u3002\u60a8\u53ef\u4ee5\u5728\u6559\u7a0b\u201c\u5982\u4f55\u5728 SQL \u4e2d\u4f7f\u7528\u6570\u5b66\u8868\u8fbe\u5f0f\u548c\u805a\u5408\u51fd\u6570\u201d\u4e2d\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u5728 SQL \u4e2d\u4f7f\u7528\u6570\u5b66\u51fd\u6570\u7684\u4fe1\u606f\u3002.<\/p>\n<p>\u4e0b\u4e00\u8282\u4e2d\uff0c\u60a8\u5c06\u4f7f\u7528 SQL \u51fd\u6570\u5904\u7406\u6570\u636e\u5e93\u4e2d\u7684\u6587\u672c\u3002.<\/p>\n<h2 id=\"%d8%a7%d8%b3%d8%aa%d9%81%d8%a7%d8%af%d9%87-%d8%a7%d8%b2-%d8%aa%d9%88%d8%a7%d8%a8%d8%b9-%d9%85%d8%aa%d9%86%db%8c\">\u4f7f\u7528\u6587\u672c\u529f\u80fd<\/h2>\n<p>SQL \u4e2d\u7684\u6587\u672c\u51fd\u6570\u53ef\u7528\u4e8e\u64cd\u4f5c\u548c\u66f4\u6539\u5b57\u7b26\u4e32\u503c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u901a\u8fc7\u5220\u9664\u4e66\u540d\u5f00\u5934\u548c\u7ed3\u5c3e\u7684\u591a\u4f59\u7a7a\u683c\uff0c\u4ee5\u66f4\u6709\u5e8f\u7684\u65b9\u5f0f\u68c0\u7d22\u4e66\u540d\u3002.<\/p>\n<p>\u4e3a\u6b64\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u8be5\u51fd\u6570\u3002 <code>\u4fee\u526a<\/code> \u4f7f\u7528\u6b64\u51fd\u6570\u53ef\u5220\u9664\u5b57\u7b26\u4e32\u5f00\u5934\u548c\u7ed3\u5c3e\u7684\u6240\u6709\u7a7a\u683c\u548c\u591a\u4f59\u5b57\u7b26\u3002.<\/p>\n<p>\u8bf7\u770b\u4ee5\u4e0b\u793a\u4f8b\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT LOWER(title) AS title_lowercase FROM inventory;\r\n<\/code><\/pre>\n<\/div>\n<p>\u5c4f\u5e55\u4e0a\u4f1a\u8f93\u51fa\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\n+------------------------------------+\r\n| title_lowercase |\r\n+------------------------------------+\r\n| the picture of dorian gray |\r\n| pride and prejudice |\r\n| the time machine |\r\n| frankenstein |\r\n| the adventures of huckleberry finn |\r\n+------------------------------------+\r\n5 rows in set (0.001 sec)\r\n<\/code><\/pre>\n<\/div>\n<p>SQL \u51fd\u6570 LOWER \u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u5e76\u5c06\u5176\u5185\u5bb9\u8f6c\u6362\u4e3a\u5c0f\u5199\u3002\u901a\u8fc7\u522b\u540d\u5217 AS title_downcase\uff0c\u8f6c\u6362\u540e\u7684\u6570\u636e\u4f1a\u5b58\u50a8\u5728\u540d\u4e3a title_downcase \u7684\u4e34\u65f6\u5217\u4e2d\u3002.<\/p>\n<p>\u73b0\u5728\u68c0\u7d22\u6240\u6709\u4f5c\u8005\uff0c\u8fd9\u6b21\u5168\u90e8\u8f6c\u6362\u4e3a\u5927\u5199\u3002\u5c1d\u8bd5\u8fd0\u884c\u4ee5\u4e0b SQL \u67e5\u8be2\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT UPPER(author) AS author_uppercase FROM inventory;\r\n<\/code><\/pre>\n<\/div>\n<p>\u60a8\u5c06\u5f97\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\n+----------------------+\r\n| author_uppercase |\r\n+----------------------+\r\n| OSCAR WILDE |\r\n| JANE AUSTEN |\r\n| HERBERT GEORGE WELLS |\r\n| MARY SHELLEY |\r\n| MARK TWAIN |\r\n+----------------------+\r\n5 rows in set (0.000 sec)<\/code><\/pre>\n<\/div>\n<p>\u60a8\u4f7f\u7528\u4e86 UPPER \u51fd\u6570\u800c\u4e0d\u662f LOWER \u51fd\u6570\uff0c\u4e24\u8005\u529f\u80fd\u7c7b\u4f3c\uff0c\u4f46 UPPER \u51fd\u6570\u4f1a\u5c06\u6587\u672c\u8f6c\u6362\u4e3a\u5927\u5199\u3002\u5982\u679c\u60a8\u5e0c\u671b\u5728\u68c0\u7d22\u6570\u636e\u65f6\u786e\u4fdd\u5927\u5c0f\u5199\u4e00\u81f4\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e24\u4e2a\u51fd\u6570\u3002.<\/p>\n<p>\u53e6\u4e00\u4e2a\u6709\u7528\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\u662f CONCAT\uff0c\u5b83\u63a5\u53d7\u591a\u4e2a\u5305\u542b\u6587\u672c\u503c\u7684\u53c2\u6570\uff0c\u5e76\u5c06\u5b83\u4eec\u8fde\u63a5\u8d77\u6765\u3002\u5c1d\u8bd5\u5c06\u4f5c\u8005\u548c\u4e66\u540d\u63d0\u53d6\u5230\u540c\u4e00\u5217\u4e2d\u3002\u4e3a\u6b64\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT CONCAT(author, ': ', title) AS full_title FROM inventory;\r\n<\/code><\/pre>\n<\/div>\n<p>\u8be5\u547d\u4ee4\u8fd4\u56de\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\">Output\r\n+------------------------------------------------+\r\n| full_title |\r\n+------------------------------------------------+\r\n| Oscar Wilde: The Picture of Dorian Gray |\r\n| Jane Austen: Pride and Prejudice |\r\n| Herbert George Wells: The Time Machine |\r\n| Mary Shelley: Frankenstein |\r\n| Mark Twain: The Adventures of Huckleberry Finn |\r\n+------------------------------------------------+\r\n5 rows in set (0.001 sec)<\/pre>\n<\/div>\n<p>CONCAT \u51fd\u6570\u7528\u4e8e\u8fde\u63a5\u591a\u4e2a\u5b57\u7b26\u4e32\uff0c\u5b83\u63a5\u53d7\u4e09\u4e2a\u53c2\u6570\u3002\u7b2c\u4e00\u4e2a\u53c2\u6570 author \u6307\u7684\u662f\u5305\u542b\u4f5c\u8005\u59d3\u540d\u7684\u4f5c\u8005\u5217\u3002\u7b2c\u4e8c\u4e2a\u53c2\u6570 :, \u662f\u4e00\u4e2a\u4efb\u610f\u5b57\u7b26\u4e32\u503c\uff0c\u7528\u4e8e\u7528\u5192\u53f7\u5206\u9694\u4f5c\u8005\u548c\u4e66\u540d\u3002\u6700\u540e\u4e00\u4e2a\u53c2\u6570 title \u6307\u7684\u662f\u5305\u542b\u4e66\u540d\u7684\u5217\u3002.<\/p>\n<p>\u67e5\u8be2\u7ed3\u679c\u4e3a\uff1a\u4f5c\u8005\u548c\u6807\u9898\u88ab\u8fd4\u56de\u5230\u4e00\u4e2a\u540d\u4e3a full_title \u7684\u4e34\u65f6\u5217\u4e2d\uff0c\u8be5\u5217\u7531\u6570\u636e\u5e93\u5f15\u64ce\u76f4\u63a5\u8fde\u63a5\u3002.<\/p>\n<p>MySQL \u5185\u7f6e\u7684\u5176\u4ed6\u5b57\u7b26\u4e32\u51fd\u6570\u5305\u62ec\u7528\u4e8e\u641c\u7d22\u548c\u66ff\u6362\u5b57\u7b26\u4e32\u3001\u68c0\u7d22\u5b50\u5b57\u7b26\u4e32\u3001\u586b\u5145\u548c\u4fee\u526a\u5b57\u7b26\u4e32\u503c\u4ee5\u53ca\u5e94\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u7b49\u7684\u51fd\u6570\u3002\u60a8\u53ef\u4ee5\u5728\u6559\u7a0b\u201c\u5982\u4f55\u4f7f\u7528 CAST \u51fd\u6570\u548c\u8fde\u63a5\u8868\u8fbe\u5f0f\u5728 SQL \u4e2d\u64cd\u4f5c\u6570\u636e\u201d\u4e2d\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u4f7f\u7528 SQL \u51fd\u6570\u8fde\u63a5\u591a\u4e2a\u503c\u7684\u4fe1\u606f\u3002\u60a8\u8fd8\u53ef\u4ee5\u53c2\u8003 MySQL \u6587\u6863\u4e2d\u7684\u201c\u5b57\u7b26\u4e32\u51fd\u6570\u548c\u8fd0\u7b97\u7b26\u201d\u90e8\u5206\u3002.<\/p>\n<p>\u4e0b\u4e00\u8282\u4e2d\uff0c\u60a8\u5c06\u4f7f\u7528 SQL \u51fd\u6570\u6765\u64cd\u4f5c\u6570\u636e\u5e93\u4e2d\u7684\u65e5\u671f\u3002.<\/p>\n<h2 id=\"%d8%a7%d8%b3%d8%aa%d9%81%d8%a7%d8%af%d9%87-%d8%a7%d8%b2-%d8%aa%d9%88%d8%a7%d8%a8%d8%b9-%d8%aa%d8%a7%d8%b1%db%8c%d8%ae-%d9%88-%d8%b2%d9%85%d8%a7%d9%86\">\u4f7f\u7528\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570<\/h2>\n<p>SQL \u4e2d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\u5141\u8bb8\u60a8\u5728\u5904\u7406 SQL \u67e5\u8be2\u65f6\u64cd\u4f5c\u5b58\u50a8\u5728\u5305\u542b\u65e5\u671f\u548c\u65f6\u95f4\u6233\u7684\u5217\u4e2d\u7684\u503c\u3002\u5b83\u4eec\u53ef\u7528\u4e8e\u63d0\u53d6\u90e8\u5206\u65e5\u671f\u4fe1\u606f\u3001\u6267\u884c\u65e5\u671f\u8ba1\u7b97\u6216\u5c06\u65e5\u671f\u548c\u65f6\u95f4\u6233\u683c\u5f0f\u5316\u4e3a\u6240\u9700\u7684\u8f93\u51fa\u683c\u5f0f\u3002.<\/p>\n<p>\u5047\u8bbe\u4f60\u9700\u8981\u5c06\u4e66\u7c4d\u7684\u51fa\u7248\u65e5\u671f\u62c6\u5206\u4e3a\u5e74\u3001\u6708\u3001\u65e5\uff0c\u800c\u4e0d\u662f\u5728\u8f93\u51fa\u4e2d\u53ea\u4fdd\u7559\u4e00\u4e2a\u65e5\u671f\u5217\u3002.<\/p>\n<p>\u8bf7\u5c1d\u8bd5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT introduction_date, YEAR(introduction_date) as year, MONTH(introduction_date) as month, DAY(introduction_date) as day FROM inventory;\r\n<\/code><\/pre>\n<\/div>\n<p>\u60a8\u5c06\u770b\u5230\u7c7b\u4f3c\u4ee5\u4e0b\u5185\u5bb9\u7684\u8f93\u51fa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\n+-------------------+------+-------+------+\r\n| introduction_date | year | month | day |\r\n+-------------------+------+-------+------+\r\n| 2022-10-01 | 2022 | 10 | 1 |\r\n| 2022-10-04 | 2022 | 10 | 4 |\r\n| 2022-09-23 | 2022 | 9 | 23 |\r\n| 2022-07-23 | 2022 | 7 | 23 |\r\n| 2022-10-01 | 2022 | 10 | 1 |\r\n+-------------------+------+-------+------+\r\n5 rows in set (0.000 sec)<\/code><\/pre>\n<\/div>\n<p>\u8fd9\u6761 SQL \u8bed\u53e5\u4f7f\u7528\u4e86\u4e09\u4e2a\u72ec\u7acb\u7684\u51fd\u6570\uff1aYEAR\u3001MONTH \u548c DAY\u3002\u6bcf\u4e2a\u51fd\u6570\u90fd\u4ee5\u5b58\u50a8\u65e5\u671f\u7684\u5217\u540d\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u5206\u522b\u63d0\u53d6\u5b8c\u6574\u65e5\u671f\u7684\u4e00\u90e8\u5206\uff1a\u5e74\u3001\u6708\u6216\u65e5\u3002\u5229\u7528\u8fd9\u4e9b\u51fd\u6570\uff0c\u60a8\u53ef\u4ee5\u5728 SQL \u67e5\u8be2\u4e2d\u8bbf\u95ee\u65e5\u671f\u7684\u5404\u4e2a\u7ec4\u6210\u90e8\u5206\u3002.<\/p>\n<p>\u53e6\u4e00\u4e2a\u7528\u4e8e\u5904\u7406\u65e5\u671f\u7684\u5b9e\u7528\u51fd\u6570\u662f DATEDIFF\uff0c\u5b83\u53ef\u4ee5\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684\u5929\u6570\u3002\u73b0\u5728\uff0c\u8bf7\u68c0\u67e5\u6bcf\u672c\u4e66\u7684\u51fa\u7248\u65e5\u671f\u4e0e\u5f53\u524d\u65e5\u671f\u4e4b\u95f4\u76f8\u9694\u4e86\u591a\u5c11\u5929\u3002.<\/p>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT introduction_date, DATEDIFF(introduction_date, CURRENT_DATE()) AS days_since FROM inventory;\r\n<\/code><\/pre>\n<\/div>\n<p>\u5c4f\u5e55\u4e0a\u4f1a\u8f93\u51fa\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\n+-------------------+------------+\r\n| introduction_date | days_since |\r\n+-------------------+------------+\r\n| 2022-10-01 | -30 |\r\n| 2022-10-04 | -27 |\r\n| 2022-09-23 | -38 |\r\n| 2022-07-23 | -100 |\r\n| 2022-10-01 | -30 |\r\n+-------------------+------------+\r\n5 rows in set (0.000 sec)<\/code><\/pre>\n<\/div>\n<p>DATEDIFF \u51fd\u6570\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff1a\u8d77\u59cb\u65e5\u671f\u548c\u7ed3\u675f\u65e5\u671f\u3002DATEDIFF \u51fd\u6570\u8ba1\u7b97\u8fd9\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684\u5929\u6570\u5dee\u3002\u5982\u679c\u7ed3\u675f\u65e5\u671f\u65e9\u4e8e\u8d77\u59cb\u65e5\u671f\uff0c\u5219\u7ed3\u679c\u53ef\u80fd\u4e3a\u8d1f\u6570\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f introduction_date \u5217\u7684\u540d\u79f0\uff0c\u8be5\u5217\u5b58\u50a8\u5e93\u5b58\u8868\u4e2d\u7684\u65e5\u671f\u3002\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u53e6\u4e00\u4e2a\u540d\u4e3a CURRENT_DATE \u7684\u51fd\u6570\uff0c\u5b83\u8868\u793a\u5f53\u524d\u7cfb\u7edf\u65e5\u671f\u3002\u8fd0\u884c\u6b64\u67e5\u8be2\u5c06\u68c0\u7d22\u8fd9\u4e24\u4e2a\u65f6\u95f4\u70b9\u4e4b\u95f4\u7684\u5929\u6570\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u540d\u4e3a days_since \u7684\u4e34\u65f6\u5217\u4e2d\u3002.<\/p>\n<p><span style=\"color: #ff0000;\">\u6ce8\u610f\uff1aDATEDIFF \u51fd\u6570\u5e76\u975e SQL \u6807\u51c6\u51fd\u6570\u96c6\u7684\u4e00\u90e8\u5206\u3002\u867d\u7136\u8bb8\u591a\u6570\u636e\u5e93\u90fd\u652f\u6301\u6b64\u51fd\u6570\uff0c\u4f46\u4e0d\u540c\u6570\u636e\u5e93\u5f15\u64ce\u7684\u8bed\u6cd5\u5f80\u5f80\u6709\u6240\u4e0d\u540c\u3002\u672c\u793a\u4f8b\u9075\u5faa MySQL \u7684\u539f\u751f\u8bed\u6cd5\u3002.<\/span><\/p>\n<p>MySQL \u5185\u7f6e\u7684\u5176\u4ed6\u65e5\u671f\u64cd\u4f5c\u51fd\u6570\u5305\u62ec\uff1a\u6dfb\u52a0\u548c\u51cf\u53bb\u65f6\u95f4\u95f4\u9694\u548c\u65e5\u671f\u3001\u4e3a\u4e0d\u540c\u8bed\u8a00\u683c\u5f0f\u683c\u5f0f\u5316\u65e5\u671f\u3001\u68c0\u7d22\u65e5\u548c\u6708\u540d\u79f0\uff0c\u4ee5\u53ca\u521b\u5efa\u65b0\u7684\u65e5\u671f\u503c\u3002\u60a8\u53ef\u4ee5\u5728\u201c\u5982\u4f55\u5728 SQL \u4e2d\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u201d\u6559\u7a0b\u4e2d\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u5728 SQL \u4e2d\u5904\u7406\u65e5\u671f\u7684\u4fe1\u606f\u3002\u60a8\u8fd8\u53ef\u4ee5\u53c2\u8003 MySQL \u6587\u6863\u4e2d\u7684\u201c\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\u201d\u90e8\u5206\u3002.<\/p>\n<p>\u4e0b\u4e00\u8282\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528\u805a\u5408\u51fd\u6570\u3002.<\/p>\n<h2 id=\"%d8%a7%d8%b3%d8%aa%d9%81%d8%a7%d8%af%d9%87-%d8%a7%d8%b2-%d8%aa%d9%88%d8%a7%d8%a8%d8%b9-%d8%ac%d9%85%d8%b9\">\u4f7f\u7528\u805a\u5408\u51fd\u6570<\/h2>\n<p>\u5728\u524d\u9762\u7684\u6240\u6709\u793a\u4f8b\u4e2d\uff0c\u60a8\u90fd\u4f7f\u7528 SQL \u51fd\u6570\u5bf9\u4e00\u884c\u4e2d\u7684\u5404\u4e2a\u5217\u503c\u8fdb\u884c\u8f6c\u6362\u6216\u8ba1\u7b97\uff0c\u8fd9\u884c\u4ee3\u8868\u4e66\u5e97\u4e2d\u7684\u4e00\u672c\u4e66\u3002SQL \u63d0\u4f9b\u4e86\u4e00\u79cd\u5bf9\u591a\u884c\u6267\u884c\u6570\u5b66\u8ba1\u7b97\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u627e\u5230\u6709\u5173\u6574\u4e2a\u6570\u636e\u96c6\u7684\u6c47\u603b\u4fe1\u606f\u3002.<\/p>\n<ul>\n<li>SQL \u4e2d\u7684\u57fa\u672c\u805a\u5408\u51fd\u6570\u5305\u62ec\uff1a<\/li>\n<li>AVG \u8868\u793a\u8fdb\u884c\u8ba1\u7b97\u6240\u7528\u6570\u503c\u7684\u5e73\u5747\u503c\u3002.<\/li>\n<li>COUNT \u7528\u4e8e\u7edf\u8ba1\u8fdb\u884c\u8ba1\u7b97\u7684\u503c\u7684\u6570\u91cf\u3002.<\/li>\n<li>MAX \u8868\u793a\u6700\u5927\u503c\u3002.<\/li>\n<li>MIN \u8868\u793a\u6700\u5c0f\u503c\u3002.<\/li>\n<li>SUM \u8868\u793a\u6240\u6709\u503c\u7684\u603b\u548c\u3002.<\/li>\n<\/ul>\n<p>\u60a8\u53ef\u4ee5\u5728 SELECT \u67e5\u8be2\u4e2d\u5305\u542b\u591a\u4e2a\u805a\u5408\u51fd\u6570\u3002\u5047\u8bbe\u60a8\u60f3\u67e5\u770b\u4e66\u5e97\u4e2d\u5217\u51fa\u7684\u4e66\u7c4d\u6570\u91cf\u3001\u6bcf\u672c\u4e66\u7684\u6700\u9ad8\u4ef7\u683c\u4ee5\u53ca\u6574\u4e2a\u4e66\u5e97\u7684\u5e73\u5747\u4ef7\u683c\u3002\u4e3a\u6b64\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT COUNT(title) AS count, MAX(price) AS max_price, AVG(price) AS avg_price FROM inventory;\r\n<\/code><\/pre>\n<\/div>\n<p>\u8be5\u547d\u4ee4\u8fd4\u56de\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\n+-------+-----------+-----------+\r\n| count | max_price | avg_price |\r\n+-------+-----------+-----------+\r\n| 5 | 42.13 | 25.106000 |\r\n+-------+-----------+-----------+\r\n1 row in set (0.001 sec)<\/code><\/pre>\n<\/div>\n<p>\u4e0a\u8ff0\u67e5\u8be2\u540c\u65f6\u4f7f\u7528\u4e86\u4e09\u4e2a\u805a\u5408\u51fd\u6570\u3002COUNT \u51fd\u6570\u7528\u4e8e\u7edf\u8ba1\u67e5\u8be2\u7ed3\u679c\u7684\u884c\u6570\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6807\u9898\u5217\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\uff0c\u4f46\u7531\u4e8e\u6bcf\u4e2a\u6807\u8bb0\u5217\u7684\u884c\u6570\u76f8\u540c\uff0c\u56e0\u6b64\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u5176\u4ed6\u5217\u540d\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u3002MAX \u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u4ef7\u683c\u5217\u4e2d\u7684\u6700\u5927\u503c\uff1a\u6b64\u5904\u5217\u540d\u5f88\u91cd\u8981\uff0c\u56e0\u4e3a\u8ba1\u7b97\u662f\u9488\u5bf9\u8be5\u5217\u4e2d\u7684\u503c\u8fdb\u884c\u7684\u3002\u6700\u540e\u4e00\u4e2a\u51fd\u6570\u662f AVG \u51fd\u6570\uff0c\u5b83\u7528\u4e8e\u8ba1\u7b97\u4ef7\u683c\u5217\u4e2d\u6240\u6709\u4ef7\u683c\u7684\u5e73\u5747\u503c\u3002.<\/p>\n<p>\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u4f7f\u7528\u805a\u5408\u51fd\u6570\uff0c\u4f1a\u5411\u6570\u636e\u5e93\u8fd4\u56de\u4e00\u884c\u6570\u636e\uff0c\u5176\u4e2d\u5305\u542b\u8868\u793a\u805a\u5408\u8ba1\u7b97\u7ed3\u679c\u7684\u4e34\u65f6\u5217\u3002\u6e90\u884c\u5728\u5185\u90e8\u7528\u4e8e\u8ba1\u7b97\uff0c\u4f46\u4e0d\u4f1a\u901a\u8fc7\u67e5\u8be2\u8fd4\u56de\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u60a8\u4f7f\u7528\u805a\u5408\u51fd\u6570\u4e00\u6b21\u6027\u8ba1\u7b97\u4e86\u6574\u4e2a\u5e93\u5b58\u8868\u4e2d\u7684\u7edf\u8ba1\u503c\uff0c\u5e76\u5728\u6c47\u603b\u65f6\u8003\u8651\u4e86\u6240\u6709\u884c\u3002.<\/p>\n<p>\u4f7f\u7528 SQL\uff0c\u60a8\u53ef\u4ee5\u5c06\u8868\u4e2d\u7684\u884c\u5206\u7ec4\uff0c\u7136\u540e\u5206\u522b\u8ba1\u7b97\u6bcf\u7ec4\u7684\u603b\u548c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u8ba1\u7b97\u4e0d\u540c\u4f5c\u8005\u4e66\u7c4d\u7684\u5e73\u5747\u4ef7\u683c\uff0c\u4ece\u800c\u627e\u51fa\u54ea\u4f4d\u4f5c\u8005\u51fa\u7248\u7684\u4e66\u7c4d\u4ef7\u683c\u6700\u9ad8\u3002\u60a8\u53ef\u4ee5\u5728\u6559\u7a0b\u201c\u5982\u4f55\u5728 SQL \u4e2d\u4f7f\u7528 GROUP BY \u548c ORDER BY\u201d\u4e2d\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u5982\u4f55\u5bf9\u884c\u8fdb\u884c\u5206\u7ec4\u4ee5\u8fdb\u884c\u6b64\u7c7b\u8ba1\u7b97\u7684\u4fe1\u606f\u3002\u60a8\u8fd8\u53ef\u4ee5\u5728\u6559\u7a0b\u201c\u5982\u4f55\u5728 SQL \u4e2d\u4f7f\u7528\u6570\u5b66\u8868\u8fbe\u5f0f\u548c\u805a\u5408\u51fd\u6570\u201d\u4e2d\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u5982\u4f55\u4f7f\u7528\u805a\u5408\u7684\u4fe1\u606f\u3002.<\/p>\n<h2 id=\"%d9%86%d8%aa%db%8c%d8%ac%d9%87\">\u7ed3\u679c<\/h2>\n<p>\u5728\u672c\u6307\u5357\u4e2d\uff0c\u60a8\u5b66\u4e60\u4e86\u5982\u4f55\u5728 SQL \u4e2d\u4f7f\u7528\u51fd\u6570\u6765\u5bf9\u6570\u636e\u8fdb\u884c\u8ba1\u7b97\u5e76\u521b\u5efa\u66f4\u590d\u6742\u7684\u67e5\u8be2\u3002\u8fd9\u4e9b\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u60a8\u4ee5\u4e0d\u540c\u7684\u65b9\u5f0f\u5904\u7406\u6570\u636e\u5e76\u83b7\u5f97\u66f4\u597d\u7684\u7ed3\u679c\u3002\u8bf7\u6ce8\u610f\uff0cSQL \u7684\u5177\u4f53\u8bed\u6cd5\u53ef\u80fd\u56e0\u60a8\u4f7f\u7528\u7684\u5173\u7cfb\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf (RDBMS) \u7684\u7c7b\u578b\u800c\u5f02\u3002.<\/p>","protected":false},"excerpt":{"rendered":"\u5f15\u8a00 \u5728\u4f7f\u7528\u5173\u7cfb\u578b\u6570\u636e\u5e93\u548c\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00 (SQL) \u65f6\uff0c\u60a8\u53ef\u4ee5\u2026\u2026","protected":false},"author":1,"featured_media":16374,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 SQL","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"","_yoast_wpseo_canonical":"","_yoast_wpseo_opengraph-description":"","_yoast_wpseo_opengraph-image":"","_yoast_wpseo_twitter-description":"","_yoast_wpseo_twitter-image":"","_yoast_wpseo_focuskeywords":"","_yoast_wpseo_primary_category":"193","footnotes":""},"categories":[193,349],"tags":[403,456],"class_list":{"0":"post-16372","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-tutorials","8":"category-database","9":"tag-data-base","10":"tag-sql"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u062f\u0631 SQL - \u0628\u0644\u0627\u06af ITPiran<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.itpiran.net\/blog\/zh\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u062f\u0631 SQL - \u0628\u0644\u0627\u06af ITPiran\" \/>\n<meta property=\"og:description\" content=\"\u0645\u0642\u062f\u0645\u0647 \u0647\u0646\u06af\u0627\u0645 \u06a9\u0627\u0631 \u0628\u0627 \u067e\u0627\u06cc\u06af\u0627\u0647\u200c\u0647\u0627\u06cc \u062f\u0627\u062f\u0647 \u0631\u0627\u0628\u0637\u0647\u200c\u0627\u06cc \u0648 \u0632\u0628\u0627\u0646 \u067e\u0631\u0633 \u0648 \u062c\u0648 \u0633\u0627\u062e\u062a\u0627\u0631 \u06cc\u0627\u0641\u062a\u0647 (SQL)\u060c \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u062f\u0627\u062f\u0647\u200c\u0647\u0627 \u0631\u0627&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.itpiran.net\/blog\/zh\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"\u0628\u0644\u0627\u06af ITPiran\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-14T22:34:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.itpiran.net\/2024\/11\/15020231\/functionsInSql.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1793\" \/>\n\t<meta property=\"og:image:height\" content=\"1110\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/person\\\/04ed27b919baca468a2273f8e4318f81\"},\"headline\":\"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u062f\u0631 SQL\",\"datePublished\":\"2024-11-14T22:34:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/\"},\"wordCount\":142,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/11\\\/15020231\\\/functionsInSql.jpg\",\"keywords\":[\"data base\",\"SQL\"],\"articleSection\":[\"\u0622\u0645\u0648\u0632\u0634\u06cc\",\"\u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/\",\"name\":\"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u062f\u0631 SQL - \u0628\u0644\u0627\u06af ITPiran\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/11\\\/15020231\\\/functionsInSql.jpg\",\"datePublished\":\"2024-11-14T22:34:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/11\\\/15020231\\\/functionsInSql.jpg\",\"contentUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/11\\\/15020231\\\/functionsInSql.jpg\",\"width\":1793,\"height\":1110},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-functions-in-sqlusing-date-and-time-functions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u0622\u0645\u0648\u0632\u0634\u06cc\",\"item\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/category\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u062f\u0631 SQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/\",\"name\":\"\u0628\u0644\u0627\u06af ITPiran\",\"description\":\"\u0627\u062e\u0628\u0627\u0631 \u0648 \u0645\u0642\u0627\u0644\u0627\u062a \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#organization\",\"name\":\"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646\",\"alternateName\":\"ITPIran Blog\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/cdn.itpiran.net\\\/2023\\\/12\\\/27150508\\\/cropped-ITPIRAN-BLOG-LOGO-2.png\",\"contentUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2023\\\/12\\\/27150508\\\/cropped-ITPIRAN-BLOG-LOGO-2.png\",\"width\":512,\"height\":512,\"caption\":\"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646\"},\"image\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/person\\\/04ed27b919baca468a2273f8e4318f81\",\"name\":\"admin\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/zh\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5982\u4f55\u5728 SQL \u4e2d\u4f7f\u7528\u51fd\u6570 - ITPiran \u535a\u5ba2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.itpiran.net\/blog\/zh\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/","og_locale":"zh_CN","og_type":"article","og_title":"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u062f\u0631 SQL - \u0628\u0644\u0627\u06af ITPiran","og_description":"\u0645\u0642\u062f\u0645\u0647 \u0647\u0646\u06af\u0627\u0645 \u06a9\u0627\u0631 \u0628\u0627 \u067e\u0627\u06cc\u06af\u0627\u0647\u200c\u0647\u0627\u06cc \u062f\u0627\u062f\u0647 \u0631\u0627\u0628\u0637\u0647\u200c\u0627\u06cc \u0648 \u0632\u0628\u0627\u0646 \u067e\u0631\u0633 \u0648 \u062c\u0648 \u0633\u0627\u062e\u062a\u0627\u0631 \u06cc\u0627\u0641\u062a\u0647 (SQL)\u060c \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u062f\u0627\u062f\u0647\u200c\u0647\u0627 \u0631\u0627&hellip;","og_url":"https:\/\/www.itpiran.net\/blog\/zh\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/","og_site_name":"\u0628\u0644\u0627\u06af ITPiran","article_published_time":"2024-11-14T22:34:07+00:00","og_image":[{"width":1793,"height":1110,"url":"https:\/\/cdn.itpiran.net\/2024\/11\/15020231\/functionsInSql.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/#article","isPartOf":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/"},"author":{"name":"admin","@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/person\/04ed27b919baca468a2273f8e4318f81"},"headline":"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u062f\u0631 SQL","datePublished":"2024-11-14T22:34:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/"},"wordCount":142,"commentCount":0,"publisher":{"@id":"https:\/\/www.itpiran.net\/blog\/#organization"},"image":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.itpiran.net\/2024\/11\/15020231\/functionsInSql.jpg","keywords":["data base","SQL"],"articleSection":["\u0622\u0645\u0648\u0632\u0634\u06cc","\u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/","url":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/","name":"\u5982\u4f55\u5728 SQL \u4e2d\u4f7f\u7528\u51fd\u6570 - ITPiran \u535a\u5ba2","isPartOf":{"@id":"https:\/\/www.itpiran.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/#primaryimage"},"image":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.itpiran.net\/2024\/11\/15020231\/functionsInSql.jpg","datePublished":"2024-11-14T22:34:07+00:00","breadcrumb":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/#primaryimage","url":"https:\/\/cdn.itpiran.net\/2024\/11\/15020231\/functionsInSql.jpg","contentUrl":"https:\/\/cdn.itpiran.net\/2024\/11\/15020231\/functionsInSql.jpg","width":1793,"height":1110},{"@type":"BreadcrumbList","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-functions-in-sqlusing-date-and-time-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.itpiran.net\/blog\/"},{"@type":"ListItem","position":2,"name":"\u0622\u0645\u0648\u0632\u0634\u06cc","item":"https:\/\/www.itpiran.net\/blog\/category\/tutorials\/"},{"@type":"ListItem","position":3,"name":"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062a\u0648\u0627\u0628\u0639 \u062f\u0631 SQL"}]},{"@type":"WebSite","@id":"https:\/\/www.itpiran.net\/blog\/#website","url":"https:\/\/www.itpiran.net\/blog\/","name":"ITPiran\u535a\u5ba2","description":"\u4f0a\u6717\u53ef\u6301\u7eed\u8d38\u6613\u65b0\u95fb\u548c\u6587\u7ae0","publisher":{"@id":"https:\/\/www.itpiran.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.itpiran.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Organization","@id":"https:\/\/www.itpiran.net\/blog\/#organization","name":"\u4f0a\u6717\u53ef\u6301\u7eed\u5546\u4e1a\u535a\u5ba2","alternateName":"ITPIran Blog","url":"https:\/\/www.itpiran.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdn.itpiran.net\/2023\/12\/27150508\/cropped-ITPIRAN-BLOG-LOGO-2.png","contentUrl":"https:\/\/cdn.itpiran.net\/2023\/12\/27150508\/cropped-ITPIRAN-BLOG-LOGO-2.png","width":512,"height":512,"caption":"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646"},"image":{"@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/person\/04ed27b919baca468a2273f8e4318f81","name":"\u884c\u653f","url":"https:\/\/www.itpiran.net\/blog\/zh\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/posts\/16372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/comments?post=16372"}],"version-history":[{"count":2,"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/posts\/16372\/revisions"}],"predecessor-version":[{"id":16375,"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/posts\/16372\/revisions\/16375"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/media\/16374"}],"wp:attachment":[{"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/media?parent=16372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/categories?post=16372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/zh\/wp-json\/wp\/v2\/tags?post=16372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}