{"id":260,"date":"2023-02-22T17:35:56","date_gmt":"2023-02-22T16:35:56","guid":{"rendered":"http:\/\/www.sepchat.com\/SC\/?p=260"},"modified":"2023-02-23T15:01:08","modified_gmt":"2023-02-23T14:01:08","slug":"sql-comment-faire-un-comptage-horizontal","status":"publish","type":"post","link":"http:\/\/www.sepchat.com\/SC\/index.php\/2023\/02\/22\/sql-comment-faire-un-comptage-horizontal\/","title":{"rendered":"SQL\u00a0&#8211; Comment faire un comptage horizontal"},"content":{"rendered":"\n<p>Exemple de comptage horizontal avec une rupture sur le code produit :<\/p>\n\n\n\n<p>select code,<br>&nbsp;&nbsp;&nbsp; sum(case VILCLI when &lsquo;ANNECY&rsquo; then 1 else 0 end) as LYON,<br>&nbsp;&nbsp;&nbsp; sum(case VILCLI when &lsquo;PARIS&rsquo; then 1 else 0 end) as PARIS,<br>&nbsp;&nbsp;&nbsp; sum(case when VILCLI not in (&lsquo;LYON&rsquo;,&rsquo;PARIS&rsquo;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then 1 else 0 end) as DIVERS<br>from clients<br>group by code&nbsp;&nbsp;&nbsp;<br>order by code&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>CODE&nbsp;&nbsp; ANNECY &nbsp; PARIS&nbsp;&nbsp;&nbsp; DIVERS&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp; A1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp; B2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp; B3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized size-full has-custom-border\"><a href=\"sql2\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.sepchat.com\/SC\/wp-content\/uploads\/2023\/02\/fleche-r-edited.png\" alt=\"\" width=\"57\" height=\"57\"\/><\/a><\/figure>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex\">\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link wp-element-button\" style=\"border-radius:100px\">Cet article vous a \u00e9t\u00e9 utile ? N\u2019h\u00e9sitez pas \u00e0 le partager.<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Exemple de comptage horizontal avec une rupture sur le code produit : select code,&nbsp;&nbsp;&nbsp; sum(case VILCLI when &lsquo;ANNECY&rsquo; then 1 else 0 end) as LYON,&nbsp;&nbsp;&nbsp; sum(case VILCLI when &lsquo;PARIS&rsquo; then 1 else 0 end) as PARIS,&nbsp;&nbsp;&nbsp; sum(case when VILCLI not in (&lsquo;LYON&rsquo;,&rsquo;PARIS&rsquo;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then 1 else 0 end) as DIVERSfrom clientsgroup by code&nbsp;&nbsp;&nbsp;order by code&nbsp;&nbsp;&nbsp;&nbsp; CODE&nbsp;&nbsp; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/posts\/260"}],"collection":[{"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/comments?post=260"}],"version-history":[{"count":3,"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/posts\/260\/revisions"}],"predecessor-version":[{"id":332,"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/posts\/260\/revisions\/332"}],"wp:attachment":[{"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/media?parent=260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/categories?post=260"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sepchat.com\/SC\/index.php\/wp-json\/wp\/v2\/tags?post=260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}