{"id":5527,"date":"2025-03-26T16:39:02","date_gmt":"2025-03-26T07:39:02","guid":{"rendered":"https:\/\/www.bold.ne.jp\/engineer-club\/?p=5527"},"modified":"2025-12-19T12:53:17","modified_gmt":"2025-12-19T03:53:17","slug":"sql-cast","status":"publish","type":"post","link":"https:\/\/www.bold.ne.jp\/engineer-club\/sql-cast","title":{"rendered":"\u3010SQL\u3011CAST\u3067\u306e\u30c7\u30fc\u30bf\u578b\u5909\u66f4\u306b\u3064\u3044\u3066\u521d\u5fc3\u8005\u5411\u3051\u306b\u308f\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac"},"content":{"rendered":"<p>CAST\u3092\u4f7f\u3046\u3068\u30c7\u30fc\u30bf\u578b\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u82f1\u5358\u8a9e\u306eCAST\u306e\u610f\u5473\u3092\u8abf\u3079\u308b\u3068\u300c\u5272\u308a\u632f\u308b\u30fb\u914d\u5f79\u3059\u308b\u30fb\u5f79\u3092\u3064\u3051\u308b\u30fb\u30fb\u300d\u306a\u3069\u306e\u65e5\u672c\u8a9e\u8a33\u304c\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u3002<br \/>\n\u30c6\u30ec\u30d3\u306a\u3069\u3067\u306f\u914d\u5f79\u306e\u3053\u3068\u3092\u30ad\u30e3\u30b9\u30c8\u3068\u8a00\u3063\u305f\u308a\u3057\u307e\u3059\u3088\u306d\u3002<\/p>\n<p>SQL\u6587\u306b\u304a\u3051\u308bCAST\u3082\u540c\u3058\u3088\u3046\u306b\u6349\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u300c\u5f79\u300d\u304c\u300c\u30c7\u30fc\u30bf\u578b\u300d\u3068\u3044\u3046\u30a4\u30e1\u30fc\u30b8\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u540c\u3058\u300c1\u300d\u3067\u3082\u6570\u5024\u578b\u306e\u5834\u5408\u3068\u6587\u5b57\u5217\u578b\u306e\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u6570\u5024\u304b\u3089\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b\u306a\u3069\u306e\u30c7\u30fc\u30bf\u578b\u306e\u5909\u66f4\u306bCAST\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#_SQL_CAST\">\uff11. SQL \u30c7\u30fc\u30bf\u578b\u3068CAST<\/a><ul><li><a href=\"#i\">\uff11-\uff11 \u30c7\u30fc\u30bf\u578b\u306b\u3064\u3044\u3066<\/a><\/li><li><a href=\"#-_CAST\">\uff11-\uff12 CAST\u3068\u306f\u9069\u5207\u306a\u30c7\u30fc\u30bf\u578b\u306b\u5909\u63db\u3059\u308b\u51e6\u7406<\/a><\/li><\/ul><\/li><li><a href=\"#_SQL_CAST-2\">\uff12. SQL CAST\u306e\u69cb\u6587<\/a><\/li><li><a href=\"#_SQL_CAST-3\">\uff13. SQL CAST\u306e\u4f7f\u3044\u3069\u3053\u308d<\/a><ul><li><a href=\"#-_CAST-2\">\uff13-\uff11 \u3069\u306e\u3088\u3046\u306a\u6642\u306bCAST\u3092\u4f7f\u3046\u306e\u304b<\/a><\/li><li><a href=\"#i-2\">\uff13-\uff12 \u5177\u4f53\u7684\u306a\u4f7f\u7528\u4f8b<\/a><\/li><\/ul><\/li><li><a href=\"#i-3\">\u307e\u3068\u3081<\/a><\/li><\/ul><\/div>\n<h2><span id=\"_SQL_CAST\">\uff11. SQL \u30c7\u30fc\u30bf\u578b\u3068CAST<\/span><\/h2>\n<p>SQL\u3067\u30c7\u30fc\u30bf\u3092\u6271\u3046\u969b\u3001\u5426\u5fdc\u306a\u3057\u306b\u30c7\u30fc\u30bf\u578b\u3092\u610f\u8b58\u3055\u305b\u3089\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u6587\u5b57\u5217\u306e\u7d50\u5408\u3067\u601d\u308f\u306c\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3001\u65e5\u4ed8\u306e\u8a08\u7b97\u3092\u3057\u305f\u3044\u304c\u30c7\u30fc\u30bf\u304c\u6587\u5b57\u5217\u578b\u3060\u3063\u305f\u306e\u3067\u8a08\u7b97\u3067\u304d\u306a\u3044\u3001JOIN\u306e\u7d50\u5408\u6761\u4ef6\u3067\u30c7\u30fc\u30bf\u578b\u304c\u7570\u306a\u308a\u7d50\u5408\u3067\u304d\u306a\u3044\u306a\u3069\u306a\u3069\u30fb\u30fb<\/p>\n<p>\u305d\u306e\u3088\u3046\u306a\u6642\u306b\u4f7f\u7528\u3067\u304d\u308b\u306e\u304cCAST\u95a2\u6570\u3067\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306fCAST\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u521d\u5fc3\u8005\u5411\u3051\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h3><span id=\"i\">\uff11-\uff11 \u30c7\u30fc\u30bf\u578b\u306b\u3064\u3044\u3066<\/span><\/h3>\n<p>\u30c7\u30fc\u30bf\u578b\u306b\u306f\u4e3b\u306b\u6b21\u306e\u3088\u3046\u306a\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong><\/strong><span class=\"f-marker-p\"><strong>\u2022 \u6570\u5024\u578b\u3000\uff08INTEGER\u3084FLOAT \u7b49\uff09 <\/strong><br \/>\n<strong>\u2022 \u6587\u5b57\u5217\u578b\u3000\uff08VARCHAR\u3084TEXT\u7b49\uff09 <\/strong><br \/>\n<strong>\u2022 \u65e5\u4ed8\u578b\u3000\uff08DATE\u3084DATETIME \u7b49\uff09<\/strong><\/span><strong><\/strong><\/p>\n<p>\u56db\u5247\u6f14\u7b97\u306f\u6570\u5024\u578b\u306e\u30c7\u30fc\u30bf\u3067\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<br \/>\n\u65e5\u4ed8\u578b\u306e\u30c7\u30fc\u30bf\u3082\u5e74\u6570\u3001\u65e5\u6570\u306a\u3069\u306e\u671f\u9593\u3092\u8a08\u7b97\u3057\u305f\u308a\u6761\u4ef6\u6307\u5b9a\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u307e\u305f\u30c7\u30fc\u30bf\u306e\u30bd\u30fc\u30c8\u3092\u3059\u308b\u969b\u306b\u6587\u5b57\u5217\u578b\u3068\u6570\u5024\u578b\u3067\u306f\u30bd\u30fc\u30c8\u3055\u308c\u308b\u9806\u5e8f\u304c\u7570\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f\u30c7\u30fc\u30bf\u578b\u306b\u3064\u3044\u3066\u7d30\u304b\u3044\u89e3\u8aac\u306f\u3057\u307e\u305b\u3093\u304c\u4ed6\u306b\u3082\u305f\u304f\u3055\u3093\u306e\u7a2e\u985e\u304c\u3042\u308a\u3001\u4f7f\u7528\u3059\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u3088\u3063\u3066\u8a18\u8ff0\u65b9\u6cd5\u3084\u4f7f\u3048\u308b\u578b\u304c\u7570\u306a\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u8a73\u7d30\u306b\u3064\u3044\u3066\u306f\u300c\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u540d \u30c7\u30fc\u30bf\u578b\u300d(\u4f8b\u3000MySQL\u30c7\u30fc\u30bf\u578b)\u306a\u3069\u3067Web\u691c\u7d22\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3><span id=\"-_CAST\">\uff11-\uff12 CAST\u3068\u306f\u9069\u5207\u306a\u30c7\u30fc\u30bf\u578b\u306b\u5909\u63db\u3059\u308b\u51e6\u7406<\/span><\/h3>\n<p>\u9069\u5207\u306a\u30c7\u30fc\u30bf\u578b\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306f\u5927\u5207\u3067\u3059\u304c\u3001\u5b9f\u306f\u308f\u3056\u308f\u3056\u5909\u63db\u3092\u884c\u308f\u306a\u304f\u3068\u3082\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u6c17\u3092\u9063\u3063\u3066\u81ea\u52d5\u7684\u306b\u578b\u5909\u63db\u3092\u3057\u3066\u304f\u308c\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\uff08\u6697\u9ed9\u7684\u578b\u5909\u63db\uff09<\/p>\n<p>\u3067\u3059\u304c\u3001\u601d\u308f\u306c\u7d50\u679c\u3084\u30a8\u30e9\u30fc\u3092\u62db\u3044\u3066\u3057\u307e\u3046\u3053\u3068\u304c\u3042\u308b\u305f\u3081\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<br \/>\n\u304d\u3061\u3093\u3068\u30c7\u30fc\u30bf\u578b\u3092\u5408\u308f\u305b\u3066\u304a\u3044\u305f\u65b9\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u3002<br \/>\n\u3000\u3000\u3000<br \/>\n\u3068\u306f\u3044\u3048\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\u306e\u30c7\u30fc\u30bf\u578b\u3092\u7c21\u5358\u306b\u5909\u66f4\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<br \/>\n\u305d\u3053\u3067CAST\u3092\u5229\u7528\u3057\u3066SQL\u6587\u306e\u4e2d\u3067\u660e\u793a\u7684\u306b\u578b\u5909\u63db\u3092\u304a\u3053\u306a\u3044\u307e\u3059\u3002<\/p>\n<p>\u4ed6\u306b\u3082\u578b\u5909\u63db\u304c\u3067\u304d\u308b\u95a2\u6570\u3068\u3057\u3066CONVERT \u304c\u3042\u308a\u307e\u3059\u304c\u3001\u672c\u8a18\u4e8b\u3067\u306fCAST\u306b\u30d5\u30a9\u30fc\u30ab\u30b9\u3057\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h2><span id=\"_SQL_CAST-2\">\uff12. SQL CAST\u306e\u69cb\u6587<\/span><\/h2>\n<div class=\"attention a-1\">\n<p><strong><\/strong><span class=\"f-marker-p\"><strong>CAST\u306e\u69cb\u6587<\/strong><\/span><br \/>\nCAST(\u5909\u63db\u3057\u305f\u3044\u30ab\u30e9\u30e0\u307e\u305f\u306f\u5024 AS \u30c7\u30fc\u30bf\u578b)<\/p>\n<\/div>\n<p>\u4f8b\uff09CAST(&#8216;2025-03-09&#8217; AS DATE)<\/p>\n<p>\u5909\u63db\u3067\u304d\u306a\u3044\u30c7\u30fc\u30bf\u306e\u5834\u5408\uff08\u3072\u3089\u304c\u306a\u3092\u6570\u5024\u306b\u3057\u3088\u3046\u3068\u3057\u305f \u306a\u3069\uff09\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2><span id=\"_SQL_CAST-3\">\uff13. SQL CAST\u306e\u4f7f\u3044\u3069\u3053\u308d<\/span><\/h2>\n<p>\u6b21\u306fCAST\u306e\u4f7f\u3044\u3069\u3053\u308d\u306b\u3064\u3044\u3066\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h3><span id=\"-_CAST-2\">\uff13-\uff11 \u3069\u306e\u3088\u3046\u306a\u6642\u306bCAST\u3092\u4f7f\u3046\u306e\u304b<\/span><\/h3>\n<p>CAST\u3067\u30c7\u30fc\u30bf\u578b\u306e\u5909\u66f4\u304c\u3067\u304d\u308b\u3053\u3068\u306f\u3053\u3053\u307e\u3067\u8aac\u660e\u3057\u3066\u304d\u305f\u901a\u308a\u3067\u3059\u304c\u3001\u5b9f\u969b\u306b\u306f\u3069\u306e\u3088\u3046\u306a\u6642\u306b\u578b\u5909\u63db\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u304b\u5177\u4f53\u4f8b\u3092\u3044\u304f\u3064\u304b\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><span class=\"f-marker-p\">(1) \u6587\u5b57\u5217\u3068\u3057\u3066\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u65e5\u4ed8\u3092\u65e5\u4ed8\u578b\u306b\u5909\u63db\u3057\u3066SELECT\u3057\u305f\u3044<br \/>\n(2) \u6570\u5024\u578b\u3067\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u6570\u5024\u3092\u6587\u5b57\u5217\u3068\u3057\u3066\u6271\u3044\u305f\u3044<br \/>\n(3) \u6587\u5b57\u5217\u578b\u306e\u6570\u5b57\u3092\u30bd\u30fc\u30c8\u3057\u305f\u3089\u60f3\u5b9a\u3068\u7570\u306a\u308b\u9806\u5e8f\u306b\u30bd\u30fc\u30c8\u3055\u308c\u3066\u3057\u307e\u3063\u305f\u3002\u756a\u53f7\u9806\u306b\u4e26\u3079\u305f\u3044\u3002<\/span><\/p>\n<h3><span id=\"i-2\">\uff13-\uff12 \u5177\u4f53\u7684\u306a\u4f7f\u7528\u4f8b<\/span><\/h3>\n<p>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u4e0a\u8a18 (1)\u304b\u3089(3) \u306e\u30b1\u30fc\u30b9\u3067\u5177\u4f53\u7684\u306a\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><span class=\"f-marker-p\">(1) \u6587\u5b57\u5217\u3068\u3057\u3066\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u65e5\u4ed8\u3092\u65e5\u4ed8\u578b\u306b\u5909\u63db\u3057\u3066SELECT\u3057\u305f\u3044<\/span><br \/>\n\u4e0b\u8868Employees\u30c6\u30fc\u30d6\u30eb\u306f1\u884c\u76ee\u304c\u30ab\u30e9\u30e0\u540d\u30012\u884c\u76ee\u306f\u30c7\u30fc\u30bf\u578b\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u540c\u3058\u8868\u306e\u306a\u304b\u3067\u5165\u793e\u65e5[Date of Employment]\u306fDate\u578b\u3067\u3059\u304c\u3001\u9000\u8077\u65e5[Retirement date]\u304c\u6587\u5b57\u5217\u578b\uff08Varchar\uff09\u3068\u306a\u3063\u3066\u3044\u308b\u305f\u3081\u3001\u30c7\u30fc\u30bf\u578b\u3092\u63c3\u3048\u305f\u72b6\u614b\u3067SELECT\u3059\u308bSQL\u6587\u3092\u8a18\u8ff0\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>Employees<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 14.8485%;\">EmpID<\/td>\n<td style=\"width: 17.0304%;\">EmpName<\/td>\n<td style=\"width: 12.2304%;\">BUnit<\/td>\n<td style=\"width: 14.9938%;\">EmpRole<\/td>\n<td style=\"width: 19.2122%;\">Date_of_Employment<\/td>\n<td style=\"width: 21.6849%;\">Retirement_date<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 14.8485%;\">int<\/td>\n<td style=\"width: 17.0304%;\">Varchar<\/td>\n<td style=\"width: 12.2304%;\">Varchar<\/td>\n<td style=\"width: 14.9938%;\">Varchar<\/td>\n<td style=\"width: 19.2122%;\">Date<\/td>\n<td style=\"width: 21.6849%;\">Varchar<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 14.8485%;\">100001<\/td>\n<td style=\"width: 17.0304%;\">\u6c5f\u6d32 \u4e45\u5f97<\/td>\n<td style=\"width: 12.2304%;\">\u672c\u90e8<\/td>\n<td style=\"width: 14.9938%;\">\u4ee3\u8868\u53d6\u7de0\u5f79\u793e\u9577<\/td>\n<td style=\"width: 19.2122%;\">1958\/3\/10<\/td>\n<td style=\"width: 21.6849%;\">2014\/1\/8<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 14.8485%;\">100230<\/td>\n<td style=\"width: 17.0304%;\">\u6c5f\u6d32 \u4e45\u6c5f\u7559<\/td>\n<td style=\"width: 12.2304%;\">\u672c\u90e8<\/td>\n<td style=\"width: 14.9938%;\">\u4ee3\u8868\u53d6\u7de0\u5f79\u793e\u9577<\/td>\n<td style=\"width: 19.2122%;\">1976\/8\/28<\/td>\n<td style=\"width: 21.6849%;\">2018\/3\/3<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 14.8485%;\">100005<\/td>\n<td style=\"width: 17.0304%;\">\u7d4c\u7406 \u4e00\u90ce<\/td>\n<td style=\"width: 12.2304%;\">\u7d4c\u7406\u90e8<\/td>\n<td style=\"width: 14.9938%;\">\u90e8\u9577<\/td>\n<td style=\"width: 19.2122%;\">1958\/3\/10<\/td>\n<td style=\"width: 21.6849%;\">2000\/5\/3<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 14.8485%;\">101707<\/td>\n<td style=\"width: 17.0304%;\">\u55b6\u696d \u6b21\u90ce<\/td>\n<td style=\"width: 12.2304%;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"width: 14.9938%;\">\u90e8\u9577<\/td>\n<td style=\"width: 19.2122%;\">1988\/10\/30<\/td>\n<td style=\"width: 21.6849%;\">1995\/12\/3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"prettyprint lang:default decode:true\">SELECT \r\n    EmpID,\r\n    EmpName,\r\n    BUnit,\r\n    EmpRole,\r\n    Date_of_Employment,\r\n    Retirement_date,\r\n    CAST(Retirement_date as date) as conversion\r\nFROM \r\n    Employees;<\/pre>\n<p>\n\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/sql-cast\/%e5%9b%b3%e5%bd%a21\" rel=\"attachment wp-att-5530\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f621.jpg\" alt=\"execution results\" width=\"1548\" height=\"257\" class=\"alignnone size-full wp-image-5530\" srcset=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f621.jpg 1548w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f621-1024x170.jpg 1024w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f621-768x128.jpg 768w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f621-1536x255.jpg 1536w\" sizes=\"(max-width: 1548px) 100vw, 1548px\" \/><\/a><\/p>\n<p>\u3000\u3000\u3000\u3000(4) \u6587\u5b57\u5217\u578b\u306e\u6570\u5b57\u3092\u30bd\u30fc\u30c8\u3057\u305f\u3089\u3001\u60f3\u5b9a\u3068\u7570\u306a\u308b\u9806\u5e8f\u306b\u30bd\u30fc\u30c8\u3055\u308c\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u756a\u53f7\u9806\u306b\u4e26\u3079\u305f\u3044<br \/>\nconversion \u30ab\u30e9\u30e0\u304c\u5909\u63db\u5f8c\u306e\u5024\u3067\u3059\u3002<br \/>\nSELECT\u6587\u306b\u306f[Retirement_date]\u3092\u6b8b\u3057\u305f\u307e\u307e\u306b\u3057\u3066\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u8868\u3067\u306f\u30c7\u30fc\u30bf\u578b\u307e\u3067\u306f\u308f\u304b\u308a\u307e\u305b\u3093\u304c\u6bd4\u3079\u3066\u3044\u305f\u3060\u304f\u3068\u8868\u793a\u30b9\u30bf\u30a4\u30eb\u304c\u5909\u308f\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><span class=\"f-marker-p\">(2) \u6570\u5024\u578b\u3067\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u6570\u5024\u3092\u6587\u5b57\u5217\u3068\u3057\u3066\u6271\u3044\u305f\u3044<\/span><br \/>\n\u5148\u7a0b\u306e\u8868 Employees\u306e EmpID\u306b\u3001\u9000\u8077\u8005\u3067\u3042\u308b\u3053\u3068\u304c\u5224\u5225\u3067\u304d\u308b\u3088\u3046ID\u306e\u5f8c\u308d\u306b\u300c\uff08\u9000\uff09\u300d\u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u7d50\u5408\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u307e\u305a\u3001EmpID\u306e int\u578b\uff08\u6570\u5024\u578b\uff09\u3092\u6587\u5b57\u5217\u578b\u306b\u5909\u63db\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">SELECT \r\n    EmpID,\r\n    CAST(EmpID AS CHAR) AS EmpID_string,\r\n    EmpName,\r\n    BUnit,\r\n    EmpRole,\r\n    Date_of_Employment,\r\n    CAST(Retirement_date AS DATE) AS conversion\r\nFROM \r\n    Employees;<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/sql-cast\/%e5%9b%b3%e5%bd%a22\" rel=\"attachment wp-att-5531\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f622.jpg\" alt=\"execution results 2\" width=\"1462\" height=\"273\" class=\"alignnone size-full wp-image-5531\" srcset=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f622.jpg 1462w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f622-1024x191.jpg 1024w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f622-768x143.jpg 768w\" sizes=\"(max-width: 1462px) 100vw, 1462px\" \/><\/a><\/p>\n<p>EmpID_string \u5217\u306f EmpID\u3068\u306f\u9055\u3044\u3001\u5de6\u5bc4\u305b\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u6587\u5b57\u5217\u3092\u7d50\u5408\u3059\u308b\u95a2\u6570[CONCAT]\u3092\u4f7f\u7528\u3057\u3066ID\u306e\u53f3\u5074\u306b\u300c\uff08\u9000\uff09\u300d\u306e\u6587\u5b57\u3092\u7d50\u5408\u3057\u307e\u3059\u3002<br \/>\n\u9000\u8077\u8005\u3060\u3051\u306b\u6587\u5b57\u3092\u8ffd\u52a0\u3057\u305f\u3044\u306e\u3067WHERE\u6587\u3067 Retirement_date \u304cNULL\u3067\u306a\u3044\u3068\u3044\u3046\u6761\u4ef6\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002\uff08\u5143\u3005\u30ea\u30b9\u30c8\u306b\u306f\u9000\u8077\u3055\u308c\u305f\u65b9\u3057\u304b\u304a\u3089\u308c\u307e\u305b\u3093\u304c\u30fb\u30fb\uff09<\/p>\n<pre class=\"prettyprint lang:default decode:true\">SELECT \r\n    CONCAT(CAST(EmpID AS CHAR) , '\uff08\u9000\uff09') AS EmpID_string,\r\n    EmpName,\r\n    BUnit,\r\n    EmpRole,\r\n    Date_of_Employment,\r\n    CAST(Retirement_date AS DATE) AS conversion\r\nFROM \r\n    Employees\r\nWHERE \r\n    Retirement_date IS NOT NULL;<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/sql-cast\/%e5%9b%b3%e5%bd%a23\" rel=\"attachment wp-att-5532\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f623.jpg\" alt=\"execution results 3\" width=\"1398\" height=\"270\" class=\"alignnone size-full wp-image-5532\" srcset=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f623.jpg 1398w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f623-1024x198.jpg 1024w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f623-768x148.jpg 768w\" sizes=\"(max-width: 1398px) 100vw, 1398px\" \/><\/a><\/p>\n<p>*\u3053\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u6697\u9ed9\u7684\u5909\u63db\u306b\u3088\u308aCAST\u3092\u3057\u306a\u304f\u3066\u3082\u7d50\u5408\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u3000\u3000\uff08MySQL8.0\u306b\u3066\u78ba\u8a8d\uff09<\/p>\n<p>\n<span class=\"f-marker-p\">(3) \u6587\u5b57\u5217\u578b\u306e\u6570\u5b57\u3092\u30bd\u30fc\u30c8\u3057\u305f\u3089\u60f3\u5b9a\u3068\u7570\u306a\u308b\u9806\u5e8f\u306b\u30bd\u30fc\u30c8\u3055\u308c\u3066\u3057\u307e\u3063\u305f\u3002\u756a\u53f7\u9806\u306b\u4e26\u3079\u305f\u3044\u3002<\/span><br \/>\n\u6b21\u306e\u3088\u3046\u306a\u30c6\u30fc\u30d6\u30eb\u304c\u3042\u308a\u307e\u3059\u3002\u30c7\u30fc\u30bf\u578b\u306f VARCHAR \u3067\u3059\u3002<\/p>\n<table style=\"border-collapse: collapse; width: 13.4545%;\">\n<tbody>\n<tr>\n<td style=\"width: 100%;\">NumberString<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 100%; text-align: left;\">1.0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 100%; text-align: left;\">10.0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 100%; text-align: left;\">2.0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 100%; text-align: left;\">21.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6587\u5b57\u5217\u578b\u3068\u3057\u3066\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\u6570\u5b57\u3092\u30bd\u30fc\u30c8(ORDER BY)\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306a\u7d50\u679c\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/sql-cast\/%e5%9b%b3%e5%bd%a24\" rel=\"attachment wp-att-5533\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f624.png\" alt=\"execution results 4\" width=\"569\" height=\"314\" class=\"alignnone size-full wp-image-5533\" \/><\/a><\/p>\n<p>\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3053\u308c\u306f\u610f\u56f3\u3057\u305f\u30bd\u30fc\u30c8\u7d50\u679c\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u3002<br \/>\n\u305d\u308c\u3067\u306f [NumberString] \u3092\u6570\u5024\u578b\u306bCAST\u3057\u3066\u304b\u3089\u30bd\u30fc\u30c8\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">SELECT NumberString\r\nFROM SampleTable\r\nORDER BY CAST(NumberString AS FLOAT);\r\n<\/pre>\n<p>\u5c0f\u6570\u30c7\u30fc\u30bf\u306e\u305f\u3081FLOAT\u578b\u306b\u5909\u63db\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/sql-cast\/%e5%9b%b3%e5%bd%a25-2\" rel=\"attachment wp-att-5535\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2025\/03\/\u56f3\u5f625.png\" alt=\"execution results 5\" width=\"574\" height=\"306\" class=\"alignnone size-full wp-image-5535\" \/><\/a><\/p>\n<p>\u60f3\u5b9a\u901a\u308a\u306b\u30bd\u30fc\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2><span id=\"i-3\">\u307e\u3068\u3081<\/span><\/h2>\n<p>\u4ee5\u4e0a\u3001\u578b\u5909\u63db\u3092\u304a\u3053\u306a\u3046 CAST \u306b\u3064\u3044\u3066\u89e3\u8aac\u3044\u305f\u3057\u307e\u3057\u305f\u3002<br \/>\n\u6700\u5f8c\u307e\u3067\u304a\u8aad\u307f\u3044\u305f\u3060\u304d\u307e\u3057\u3066\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\n\u3010\u53c2\u8003\u30b5\u30a4\u30c8\u3011<br \/>\n<a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/ja\/cast-functions.html\" class=\"broken_link\">12.11 \u30ad\u30e3\u30b9\u30c8\u95a2\u6570\u3068\u6f14\u7b97\u5b50<\/a><br \/>\n<a href=\"https:\/\/docs.microsoft.com\/ja-jp\/sql\/t-sql\/functions\/cast-and-convert-transact-sql?view=sql-server-ver15\">CAST \u304a\u3088\u3073 CONVERT (Transact-SQL) \u2013 SQL Server | Microsoft Docs<\/a><br \/>\n<a href=\"https:\/\/learn.microsoft.com\/ja-jp\/sql\/t-sql\/data-types\/data-type-conversion-database-engine?view=sql-server-ver16\">\u30c7\u30fc\u30bf\u578b\u306e\u5909\u63db (\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 \u30a8\u30f3\u30b8\u30f3) &#8211; SQL Server | Microsoft Learn<\/a><\/p>\n<p>\u3010\u52d5\u4f5c\u691c\u8a3cDB\u3011<br \/>\nmySQL 8.0.39<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CAST\u3092\u4f7f\u3046\u3068\u30c7\u30fc\u30bf\u578b\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u82f1\u5358\u8a9e\u306eCAST\u306e\u610f\u5473\u3092\u8abf\u3079\u308b\u3068\u300c\u5272\u308a\u632f\u308b\u30fb\u914d\u5f79\u3059\u308b\u30fb\u5f79\u3092\u3064\u3051\u308b\u30fb\u30fb\u300d\u306a\u3069\u306e\u65e5\u672c\u8a9e\u8a33\u304c\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u3002 \u30c6\u30ec\u30d3\u306a\u3069\u3067\u306f\u914d\u5f79\u306e\u3053\u3068\u3092\u30ad\u30e3\u30b9\u30c8\u3068\u8a00\u3063\u305f\u308a\u3057\u307e\u3059\u3088\u306d\u3002 SQL [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":5437,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/5527"}],"collection":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/comments?post=5527"}],"version-history":[{"count":4,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/5527\/revisions"}],"predecessor-version":[{"id":6282,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/5527\/revisions\/6282"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media\/5437"}],"wp:attachment":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media?parent=5527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/categories?post=5527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}