{"id":312,"date":"2017-09-24T21:53:32","date_gmt":"2017-09-24T12:53:32","guid":{"rendered":"https:\/\/www.oqiita.com\/?p=312"},"modified":"2018-06-07T10:48:15","modified_gmt":"2018-06-07T01:48:15","slug":"post-312","status":"publish","type":"post","link":"https:\/\/www.oqiita.com\/?p=312","title":{"rendered":"\u3010GeneXus\u3011Sum\u30fbCount\u30fbAverage\u30fbMax\u30fbMin"},"content":{"rendered":"<p>Sum\u3001Count\u3001Average\u3001Max\u3001Min\u3001\u306b\u3064\u3044\u3066\u691c\u8a3c\u3068\u3044\u3046\u3053\u3068\u3067\u6295\u7a3f\u3002<\/p>\n<p><!--more--><br \/>\n  <a class=\"reference table\" href=\"http:\/\/wiki.genexus.jp\/hwiki.aspx?Sum%E3%80%81Count%E3%80%81Average+%E5%BC%8F\" target=\"_blank\" rel=\"noopener noreferrer\"><br \/>\n    <span class=\"tbcell refttl\">\u53c2\u8003<\/span><br \/>\n    <span class=\"tbcell refcite\">Sum\u3001Count\u3001Average \u5f0f<span>wiki.genexus.jp<\/span><\/span><br \/>\n  <\/a><br \/>\n  <a class=\"reference table\" href=\"http:\/\/wiki.genexus.jp\/hwiki.aspx?Max+%E5%BC%8F%E3%80%81Min+%E5%BC%8F\" target=\"_blank\" rel=\"noopener noreferrer\"><br \/>\n    <span class=\"tbcell refttl\">\u53c2\u8003<\/span><br \/>\n    <span class=\"tbcell refcite\">Max \u5f0f\u3001Min \u5f0f<span>wiki.genexus.jp<\/span><\/span><br \/>\n  <\/a><\/p>\n<p><\/p>\n<h3 id=\"i-0\">\u60f3\u5b9a\u74b0\u5883<\/h3>\n<p>GeneXus X Ev3 u14<br \/>\nDB\uff1aMYSQL<br \/>\n\u8a00\u8a9e\uff1aJava<\/p>\n<h3 id=\"i-1\">\u30c7\u30fc\u30bf<\/h3>\n<p>\u5546\u54c1\u30de\u30b9\u30bf\u306b\u30c7\u30fc\u30bf\u304c\u3042\u308b\u611f\u3058\u3067\u3059\u3002<br \/>\n<a href=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/m_product.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/m_product-1024x393.png\" alt=\"\" width=\"680\" height=\"261\" class=\"alignnone size-large wp-image-317\" srcset=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/m_product-1024x393.png 1024w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/m_product-300x115.png 300w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/m_product-768x295.png 768w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/m_product-320x123.png 320w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/m_product.png 1080w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\"><\/a><br \/>\n<a href=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/\u30c7\u30fc\u30bf.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/\u30c7\u30fc\u30bf.png\" alt=\"\" width=\"465\" height=\"311\" class=\"alignnone size-full wp-image-313\" srcset=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/\u30c7\u30fc\u30bf.png 465w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/\u30c7\u30fc\u30bf-300x201.png 300w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/\u30c7\u30fc\u30bf-320x214.png 320w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\"><\/a><\/p>\n<h3 id=\"i-2\">Sum<\/h3>\n<p>\u5408\u8a08\u3092\u6c42\u3081\u308b\u95a2\u6570\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-gx\">\/\/ \u5168\u3066\u306e\u5546\u54c1\u4fa1\u683c\u306e\u5408\u8a08\u3092\u53d6\u5f97\u3002\n&amp;Num = Sum(product_price)\n<\/code><\/pre>\n<h3 id=\"i-3\">Count<\/h3>\n<p>\u500b\u6570\u3092\u6c42\u3081\u308b\u95a2\u6570\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-gx\">\/\/ \u5546\u54c1\u30de\u30b9\u30bf\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\u306e\u6570\u3092\u53d6\u5f97\u3002\n&amp;Num = Count(product_id)\n<\/code><\/pre>\n<h3 id=\"i-4\">Average<\/h3>\n<p>\u5e73\u5747\u3092\u6c42\u3081\u308b\u95a2\u6570\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-gx\">\/\/ \u5546\u54c1\u4fa1\u683c\u306e\u5e73\u5747\u5024\u3092\u53d6\u5f97\u3002\n&amp;Num = Average(product_price)\n<\/code><\/pre>\n<h3 id=\"i-5\">Max<\/h3>\n<p>\u6700\u5927\u5024\u3092\u6c42\u3081\u308b\u95a2\u6570\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-gx\">\/\/ \u5546\u54c1\u4fa1\u683c\u306e\u6700\u5927\u5024\u3092\u53d6\u5f97\u3002\n&amp;Num = Max(product_price)\n<\/code><\/pre>\n<h3 id=\"i-6\">Min<\/h3>\n<p>\u6700\u5c0f\u5024\u3092\u6c42\u3081\u308b\u95a2\u6570\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-gx\">\/\/ \u5546\u54c1\u4fa1\u683c\u306e\u6700\u5c0f\u5024\u3092\u53d6\u5f97\u3002\n&amp;Num = Min(product_price)\n<\/code><\/pre>\n<h3 id=\"i-7\">\u7d50\u679c<\/h3>\n<p><a href=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result.png\" alt=\"\" width=\"510\" height=\"356\" class=\"alignnone size-full wp-image-319\" srcset=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result.png 510w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result-300x209.png 300w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result-320x223.png 320w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\"><\/a><\/p>\n<h3 id=\"i-8\">\u5b9f\u884c\u3055\u308c\u308bSQL<\/h3>\n<p>GeneXus\u304c\u767a\u884c\u3057\u3066MYSQL\u3067\u5b9f\u884c\u3057\u3066\u3044\u308bSQL\u3067\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">-- SUM\nSELECT COALESCE( T1.`GXC1`, 0) AS GXC1 FROM (SELECT SUM(`product_price`) AS GXC1 FROM `m_product` ) T1\n\n-- COUNT\nSELECT COALESCE( T1.`GXC2`, 0) AS GXC2 FROM (SELECT COUNT(*) AS GXC2 FROM `m_product` ) T1\n\n-- AVERAGE\nSELECT COALESCE( T1.`GXC3`, 0) AS GXC3 FROM (SELECT AVG(`product_price`) AS GXC3 FROM `m_product` ) T1\n\n-- MAX\nSELECT COALESCE( T1.`GXC4`, 0) AS GXC4 FROM (SELECT MAX(`product_price`) AS GXC4 FROM `m_product` ) T1\n\n-- MIN\nSELECT COALESCE( T1.`GXC5`, 0) AS GXC5 FROM (SELECT MIN(`product_price`) AS GXC5 FROM `m_product` ) T1\n<\/code><\/pre>\n<p>\u203b\u4e0a\u8a18\u306eSQL\u78ba\u8a8d\u65b9\u6cd5\u306fJDBC\u306e\u30ed\u30b0\u3092\u51fa\u529b\u3059\u308b\u304b\u3001MYSQL\u306e\u5834\u5408\u306f\u4ee5\u4e0b\u306eini\u30d5\u30a1\u30a4\u30eb\u3092\u5909\u66f4\u3059\u308c\u3070\u30ed\u30b0\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u300cC:\\ProgramData\\MySQL\\MySQL Server 5.6\\my.ini\u300d\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-ini\">\nlog-output=FILE\ngeneral-log=1\ngeneral_log_file=\"[PC\u540d].log\"\nslow-query-log=1\nslow_query_log_file=\"[PC\u540d]-slow.log\"\nlong_query_time=10\n\n<\/code><\/pre>\n<h3 id=\"i-9\">\u5f15\u6570\u306e\u8ffd\u52a0\uff08Count\u3001Sum\u3001Average\uff09<\/h3>\n<p>Count\u3001Sum\u3001Average\u306f\u691c\u7d22\u6761\u4ef6\u3068\u521d\u671f\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u7b2c1\u5f15\u6570\uff1a\u8a08\u7b97\u5bfe\u8c61\u306e\u9805\u76ee<br \/>\n\u7b2c2\u5f15\u6570\uff1a\u691c\u7d22\u6761\u4ef6<br \/>\n\u7b2c3\u5f15\u6570\uff1a\u521d\u671f\u5024<\/p>\n<h4 id=\"i-10\">\u30b3\u30fc\u30c9<\/h4>\n<pre class=\"line-numbers\"><code class=\"language-gx\">\n\/\/ \u300c\u5546\u54c1\u533a\u5206\uff1a\u98df\u3079\u7269\u300d\u306e\u5546\u54c1\u4fa1\u683c\u306e\u5408\u8a08\u3092\u53d6\u5f97\u3002\n&amp;Num = Sum(product_price, product_kbn = ProductKbn.Food, 0)\n\n\/\/ \u300c\u5546\u54c1\u533a\u5206\uff1a\u98df\u3079\u7269\u300d\u306e\u5546\u54c1\u30c7\u30fc\u30bf\u306e\u6570\u3092\u53d6\u5f97\u3002\n&amp;Num = Count(product_id, product_kbn = ProductKbn.Food, 0)\n\n\/\/ \u300c\u5546\u54c1\u533a\u5206\uff1a\u98df\u3079\u7269\u300d\u306e\u5546\u54c1\u4fa1\u683c\u306e\u5e73\u5747\u5024\u3092\u53d6\u5f97\u3002\n&amp;Num = Average(product_price, product_kbn = ProductKbn.Food, 0)\n\n<\/code><\/pre>\n<h4 id=\"i-11\">\u7d50\u679c<\/h4>\n<p><a href=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result2.png\" alt=\"\" width=\"505\" height=\"347\" class=\"alignnone size-full wp-image-324\" srcset=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result2.png 505w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result2-300x206.png 300w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result2-320x220.png 320w\" sizes=\"auto, (max-width: 505px) 100vw, 505px\"><\/a><\/p>\n<h4 id=\"i-12\">\u5b9f\u884c\u3055\u308c\u308bSQL<\/h4>\n<pre class=\"line-numbers\"><code class=\"language-sql\">-- SUM\nSELECT COALESCE( T1.`GXC1`, 0) AS GXC1 FROM (SELECT SUM(`product_price`) AS GXC1 FROM `m_product` WHERE `product_kbn` = 1 ) T1\n\n-- COUNT\nSELECT COALESCE( T1.`GXC2`, 0) AS GXC2 FROM (SELECT COUNT(*) AS GXC2 FROM `m_product` WHERE `product_kbn` = 1 ) T1\n\n-- AVERAGE\nSELECT COALESCE( T1.`GXC3`, 0) AS GXC3 FROM (SELECT AVG(`product_price`) AS GXC3 FROM `m_product` WHERE `product_kbn` = 1 ) T1\n<\/code><\/pre>\n<h3 id=\"i-13\">\u5f15\u6570\u306e\u8ffd\u52a0\uff08Max\u3001Min\uff09<\/h3>\n<p>Max\u3001Min\u306f\u691c\u7d22\u6761\u4ef6\u3068\u521d\u671f\u5024\u3001\u3055\u3089\u306b\u3069\u306e\u9805\u76ee\u3092\u53d6\u5f97\u3059\u308b\u304b\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u7b2c1\u5f15\u6570\uff1a\u8a08\u7b97\u5bfe\u8c61\u306e\u9805\u76ee<br \/>\n\u7b2c2\u5f15\u6570\uff1a\u691c\u7d22\u6761\u4ef6<br \/>\n\u7b2c3\u5f15\u6570\uff1a\u521d\u671f\u5024<br \/>\n\u7b2c4\u5f15\u6570\uff1a\u53d6\u5f97\u9805\u76ee<\/p>\n<h4 id=\"i-14\">\u30b3\u30fc\u30c9<\/h4>\n<pre class=\"line-numbers\"><code class=\"language-gx\">\n\/\/ \u300c\u5546\u54c1\u533a\u5206\uff1a\u98df\u3079\u7269\u300d\u3067\u5546\u54c1\u4fa1\u683c\u304c\u6700\u5927\u5024\u306e\u5546\u54c1\u540d\u79f0\u3092\u53d6\u5f97\u3002\n&amp;Var = Max(product_price, product_kbn = ProductKbn.Food, \"\", product_name)\n\n\/\/ \u300c\u5546\u54c1\u533a\u5206\uff1a\u98df\u3079\u7269\u300d\u3067\u5546\u54c1\u4fa1\u683c\u304c\u6700\u5c0f\u5024\u306e\u5546\u54c1\u540d\u79f0\u3092\u53d6\u5f97\u3002\n&amp;Var = Min(product_price, product_kbn = ProductKbn.Food, \"\", product_name)\n\n<\/code><\/pre>\n<h4 id=\"i-15\">\u7d50\u679c<\/h4>\n<p><a href=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result3.png\" alt=\"\" width=\"510\" height=\"351\" class=\"alignnone size-full wp-image-327\" srcset=\"https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result3.png 510w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result3-300x206.png 300w, https:\/\/www.oqiita.com\/wp-content\/uploads\/2017\/09\/Result3-320x220.png 320w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\"><\/a><\/p>\n<h4 id=\"i-16\">\u5b9f\u884c\u3055\u308c\u308bSQL<\/h4>\n<pre class=\"line-numbers\"><code class=\"language-sql\">\n-- MAX\nSELECT COALESCE( T1.`GXC4`, '') AS GXC4 FROM \n\t(SELECT MIN(T2.`product_name`) AS GXC4 FROM `m_product` T2,  \n\t(SELECT MAX(`product_price`) AS GXC6 FROM `m_product` WHERE `product_kbn` = 1 ) T3 \nWHERE (T2.`product_price` = T3.`GXC6`) AND (T2.`product_kbn` = 1) ) T1\n\n-- MIN\nSELECT COALESCE( T1.`GXC5`, '') AS GXC5 FROM \n\t(SELECT MIN(T2.`product_name`) AS GXC5 FROM `m_product` T2,  \n\t(SELECT MIN(`product_price`) AS GXC7 FROM `m_product` WHERE `product_kbn` = 1 ) T3 \nWHERE (T2.`product_price` = T3.`GXC7`) AND (T2.`product_kbn` = 1) ) T1\n\n<\/code><\/pre>\n<p><del datetime=\"2017-09-24T12:50:36+00:00\">\u2191\u3084\u3084\u3053\u3057\u3044SQL\u3060\u306a<\/del><\/p>\n<hr>\n<p>\u3068\u308a\u3042\u3048\u305a\u7c21\u5358\u306a\u3068\u3053\u308d\u304b\u3089\u6295\u7a3f\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u691c\u7d22\u6761\u4ef6\u3068\u304b\u8ffd\u52a0\u3067\u304d\u3066\u4fbf\u5229\u3067\u3059\u306d( ^\u03c9^ )\uff86\uff7a\uff86\uff7a<\/p>\n<p>\u305f\u3060\u4eca\u56de\u7d39\u4ecb\u3057\u305fSum\u30fbCount\u30fbAverage\u30fbMax\u30fbMin\u3067\u3059\u304c<br \/>\nFor each\u306e\u9014\u4e2d\u3068\u304b\u3067\u3084\u308b\u3068\u30ef\u30b1\u30ef\u30ab\u30e9\u30f3\u7d50\u679c\u3092\u8fd4\u3059\u3068\u304d\u304c\u3042\u308b\u306e\u3067<br \/>\n\u5b9f\u88c5\u3059\u308b\u5834\u5408\u306f\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u3092\u898b\u3066\u3001\u81ea\u5206\u306e\u601d\u3063\u3066\u3044\u308b\u901a\u308a\u52d5\u3044\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u306a\u304c\u3089\u5b9f\u88c5\u3057\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sum\u3001Count\u3001Average\u3001Max\u3001Min\u3001\u306b\u3064\u3044\u3066\u691c\u8a3c\u3068\u3044\u3046\u3053\u3068\u3067\u6295\u7a3f\u3002<\/p>\n","protected":false},"author":1,"featured_media":722,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[48,45,37,51,46,47,50,49],"class_list":{"0":"post-312","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-genexus","8":"tag-average","9":"tag-count","10":"tag-genexus","11":"tag-java","12":"tag-max","13":"tag-min","14":"tag-mysql","15":"tag-sum","16":"entry"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.oqiita.com\/wp-content\/uploads\/2018\/05\/sango_gx_icatch.png","jetpack_shortlink":"https:\/\/wp.me\/p8QluP-52","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.oqiita.com\/index.php?rest_route=\/wp\/v2\/posts\/312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oqiita.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oqiita.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oqiita.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oqiita.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=312"}],"version-history":[{"count":20,"href":"https:\/\/www.oqiita.com\/index.php?rest_route=\/wp\/v2\/posts\/312\/revisions"}],"predecessor-version":[{"id":846,"href":"https:\/\/www.oqiita.com\/index.php?rest_route=\/wp\/v2\/posts\/312\/revisions\/846"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.oqiita.com\/index.php?rest_route=\/wp\/v2\/media\/722"}],"wp:attachment":[{"href":"https:\/\/www.oqiita.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oqiita.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oqiita.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}