{"id":131,"date":"2021-03-31T15:39:16","date_gmt":"2021-03-31T06:39:16","guid":{"rendered":"http:\/\/www.agile-software.site\/?p=131"},"modified":"2025-12-21T09:12:32","modified_gmt":"2025-12-21T00:12:32","slug":"sql","status":"publish","type":"post","link":"https:\/\/agile-software.net\/?p=131","title":{"rendered":"SQL"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9<\/h2>\n\n\n\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u3084\u6570\u5024\u306a\u3069\u306e\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3059\u308b\u305f\u3081\u306e\u30c4\u30fc\u30eb\u3067\u3059<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u547d\u4ee4\uff08\u30af\u30a8\u30ea\uff09<\/strong>\u3092\u9001\u308b\u3053\u3068\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002\nSQL\u306f\u30af\u30a8\u30ea\u3092\u66f8\u304f\u305f\u3081\u306e\u8a00\u8a9e<\/pre>\n\n\n\n<div class=\"wp-block-jin-gb-block-box-with-headline kaisetsu-box1\"><div class=\"kaisetsu-box1-title\">\u964d\u3079\u304d\u306e\u9806<\/div>\n<p>order by ASC<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-jin-gb-block-box-with-headline kaisetsu-box1\"><div class=\"kaisetsu-box1-title\">\u30b0\u30eb\u30fc\u30d7\u3054\u3068\u306b<\/div>\n<p>group by<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">SQL\u306e\u300c3\u3064\u306e\u968e\u5c64\u300d\u3092\u7406\u89e3\u3059\u308b<\/h2>\n\n\n\n<p>SQL\u306f\u30d0\u30e9\u30d0\u30e9\u306a\u5358\u8a9e\u306e\u96c6\u307e\u308a\u3067\u306f\u306a\u304f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u300c\u968e\u5c64\u69cb\u9020\u300d\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2460 \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\uff08\u6587\uff09<\/h3>\n\n\n\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u300c\u4f55\u3092\u3059\u308b\u304b\u300d\u3092\u6307\u793a\u3059\u308b\u3001\u6700\u3082\u5927\u304d\u306a\u5358\u4f4d\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SELECT<\/strong>\uff08\u30c7\u30fc\u30bf\u3092\u53c2\u7167\u305b\u3088\uff09<\/li>\n\n\n\n<li><strong>INSERT<\/strong>\uff08\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u305b\u3088\uff09<\/li>\n\n\n\n<li><strong>UPDATE<\/strong>\uff08\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\u305b\u3088\uff09<\/li>\n\n\n\n<li><strong>DELETE<\/strong>\uff08\u30c7\u30fc\u30bf\u3092\u524a\u9664\u305b\u3088\uff09<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u2461 \u53e5\uff08Clause\uff09<\/h3>\n\n\n\n<p>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u4e2d\u306b\u3042\u308b\u3001\u5f79\u5272\u3054\u3068\u306e\u300c\u30d6\u30ed\u30c3\u30af\u300d\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SELECT\u53e5<\/strong>\uff08\u3069\u306e\u5217\u3092\uff1f\uff09<\/li>\n\n\n\n<li><strong>FROM\u53e5<\/strong>\uff08\u3069\u306e\u30c6\u30fc\u30d6\u30eb\u304b\u3089\uff1f\uff09<\/li>\n\n\n\n<li><strong>WHERE\u53e5<\/strong>\uff08\u3069\u3093\u306a\u6761\u4ef6\u3067\uff1f\uff09<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u2462 \u30ad\u30fc\u30ef\u30fc\u30c9 \/ \u4fee\u98fe\u5b50<\/h3>\n\n\n\n<p>\u53e5\u306e\u4e2d\u3067\u300c\u3069\u3046\u632f\u308b\u821e\u3046\u304b\u300d\u3068\u3044\u3046\u7d30\u304b\u3044\u30eb\u30fc\u30eb\u3092\u6307\u5b9a\u3059\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">DISTINCT<\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>SELECT DISTINCT user_id\nFROM sales_log;<\/code><\/pre><\/div>\n\n\n\n<p><strong>SELECT<\/strong>: \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\uff08\u6307\u793a\u6587\uff09\uff1d\u300c\u53d6\u308c\uff01\u300d<br><strong>DISTINCT<\/strong>: \u4fee\u98fe\u5b50\uff08\u30ad\u30fc\u30ef\u30fc\u30c9\uff09\uff1d\u300c\u305f\u3060\u3057\u3001\u91cd\u8907\u306f\u9664\u3044\u3066\u306a\uff01\u300d<\/p>\n\n\n\n<p>\u4e3b\u5f79\u306f\u3042\u304f\u307e\u3067<code>SELECT<\/code>\u3067\u3042\u308a\u3001<code>DISTINCT<\/code>\u306f\u300c\u53d6\u308a\u65b9\u300d\u306b\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0\u3057\u3066\u3044\u308b\u6dfb\u3048\u5b57\u306e\u3088\u3046\u306a\u5b58\u5728\u3067\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">AS<\/h4>\n\n\n\n<p>\u5217\u540d\u3084\u30c6\u30fc\u30d6\u30eb\u540d\u306b\u300c\u4e00\u6642\u7684\u306a\u3042\u3060\u540d\u300d\u3092\u3064\u3051\u308b\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5f79\u5272:<\/strong>\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u8aad\u307f\u3084\u3059\u304f\u3059\u308b:<\/strong> <code>count(*)<\/code> \u306e\u3088\u3046\u306a\u8a08\u7b97\u7d50\u679c\u306b <code>AS total_count<\/code> \u3068\u540d\u524d\u3092\u3064\u3051\u3066\u5206\u304b\u308a\u3084\u3059\u304f\u3059\u308b\u3002<\/li>\n\n\n\n<li><strong>\u77ed\u7e2e\u3059\u308b:<\/strong> \u9577\u3044\u30c6\u30fc\u30d6\u30eb\u540d\u3092 <code>AS t1<\/code> \u3068\u7565\u3057\u3066\u3001\u7d50\u5408\uff08JOIN\uff09\u306e\u8a18\u8ff0\u3092\u697d\u306b\u3059\u308b\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u4f8b:<\/strong> <code>SELECT user_name AS name FROM users;<\/code> \uff08user_name\u5217\u3092\u3001\u7d50\u679c\u753b\u9762\u3067\u306f name \u3068\u3057\u3066\u8868\u793a\u305b\u3088\uff09<\/p>\n<\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\">ASC \/ DESC<\/h4>\n\n\n\n<p><code>ORDER BY<\/code> \u53e5\u306e\u4e2d\u3067\u3001\u30c7\u30fc\u30bf\u306e\u4e26\u3073\u65b9\u3092\u6307\u5b9a\u3059\u308b\u305f\u3081\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ASC (Ascending):<\/strong> \u6607\u9806\uff08\u5c0f\u3055\u3044\u9806\u3001\u3042\u3044\u3046\u3048\u304a\u9806\u3001\u53e4\u3044\u9806\uff09\u3002<strong>\u30c7\u30d5\u30a9\u30eb\u30c8\uff08\u7701\u7565\u6642\uff09\u306f\u3053\u3061\u3089<\/strong>\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>DESC (Descending):<\/strong> \u964d\u9806\uff08\u5927\u304d\u3044\u9806\u3001\u9006\u5f15\u304d\u9806\u3001\u65b0\u3057\u3044\u9806\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>TOP \/ LIMIT<\/strong><\/h4>\n\n\n\n<p>\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u304c\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u3067\u3001\u3068\u308a\u3042\u3048\u305a\u4e2d\u8eab\u3092\u6570\u4ef6\u3060\u3051\u78ba\u8a8d\u3057\u305f\u3044\u6642\u3084\u3001\u30e9\u30f3\u30ad\u30f3\u30b0\u306e\u4e0a\u4f4d\u3060\u3051\u304c\u6b32\u3057\u3044\u6642\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5f79\u5272:<\/strong> \u6700\u7d42\u7684\u306b\u51fa\u529b\u3059\u308b\u884c\u6570\u306b\u300c\u4e0a\u9650\u300d\u3092\u8a2d\u3051\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u6ce8\u610f\u70b9:<\/strong> \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u88fd\u54c1\u306b\u3088\u3063\u3066\u66f8\u304d\u65b9\u304c\u7570\u306a\u308a\u307e\u3059\u3002\n<ul class=\"wp-block-list\">\n<li><strong>PostgreSQL \/ MySQL \/ Snowflake:<\/strong> <code>LIMIT 10<\/code> (\u6587\u306e\u6700\u5f8c\u306b\u66f8\u304f)<\/li>\n\n\n\n<li><strong>SQL Server:<\/strong> <code>SELECT TOP 10<\/code> (SELECT\u306e\u76f4\u5f8c\u306b\u66f8\u304f)<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u30bb\u30c3\u30c8\u3067\u4f7f\u3046\u3079\u304d\u53e5:<\/strong> <code>ORDER BY<\/code> \u3067\u3059\u3002\u300c\u4f55\u3092\u3082\u3063\u3066\u4e0a\u304b\u3089\u3068\u3059\u308b\u304b\u300d\u3092\u6c7a\u3081\u306a\u3044\u3068\u3001\u5b9f\u884c\u3059\u308b\u305f\u3073\u306b\u7d50\u679c\u304c\u5909\u308f\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u3084\u6570\u5024\u306a\u3069\u306e\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3059\u308b\u305f\u3081\u306e\u30c4\u30fc\u30eb\u3067\u3059 \u547d\u4ee4\uff08\u30af\u30a8\u30ea\uff09\u3092\u9001\u308b\u3053\u3068\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002 SQL\u306f\u30af\u30a8\u30ea\u3092\u66f8\u304f\u305f\u3081\u306e\u8a00\u8a9e SQL\u306e\u300c3\u3064\u306e\u968e\u5c64\u300d\u3092\u7406\u89e3<\/p>\n","protected":false},"author":1,"featured_media":349,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=131"}],"version-history":[{"count":5,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":3285,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions\/3285"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/media\/349"}],"wp:attachment":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}