MySQL Query with count(*) and group by











up vote
-2
down vote

favorite












I have a table (wccrm_anprobe) with a model, a branch, a date and a state. I need to have a list ordered by month, branch and then a count(*) by model where state = 1



I have attached an Image to visualise how it should looks like.



Thank you for any help![It should look like this]1



I tried with that SQL Statement:



SELECT COUNT(*), model, branch, date
FROM wccrm_anprobe
GROUP BY date , branch


But the output is just the days and the number of models, and not all date merged into months...



Best Regards,



Stefan










share|improve this question




















  • 1




    and what SQL have you tried thus far?
    – treyBake
    Nov 19 at 17:04






  • 2




    Question examples using images are bad i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 19 at 17:04








  • 1




    Hint: SELECT <some_columns>, COUNT(*) ... WHERE state = 1 GROUP BY <some_columns>.. Keep <some_columns> the same..
    – Raymond Nijland
    Nov 19 at 17:06

















up vote
-2
down vote

favorite












I have a table (wccrm_anprobe) with a model, a branch, a date and a state. I need to have a list ordered by month, branch and then a count(*) by model where state = 1



I have attached an Image to visualise how it should looks like.



Thank you for any help![It should look like this]1



I tried with that SQL Statement:



SELECT COUNT(*), model, branch, date
FROM wccrm_anprobe
GROUP BY date , branch


But the output is just the days and the number of models, and not all date merged into months...



Best Regards,



Stefan










share|improve this question




















  • 1




    and what SQL have you tried thus far?
    – treyBake
    Nov 19 at 17:04






  • 2




    Question examples using images are bad i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 19 at 17:04








  • 1




    Hint: SELECT <some_columns>, COUNT(*) ... WHERE state = 1 GROUP BY <some_columns>.. Keep <some_columns> the same..
    – Raymond Nijland
    Nov 19 at 17:06















up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I have a table (wccrm_anprobe) with a model, a branch, a date and a state. I need to have a list ordered by month, branch and then a count(*) by model where state = 1



I have attached an Image to visualise how it should looks like.



Thank you for any help![It should look like this]1



I tried with that SQL Statement:



SELECT COUNT(*), model, branch, date
FROM wccrm_anprobe
GROUP BY date , branch


But the output is just the days and the number of models, and not all date merged into months...



Best Regards,



Stefan










share|improve this question















I have a table (wccrm_anprobe) with a model, a branch, a date and a state. I need to have a list ordered by month, branch and then a count(*) by model where state = 1



I have attached an Image to visualise how it should looks like.



Thank you for any help![It should look like this]1



I tried with that SQL Statement:



SELECT COUNT(*), model, branch, date
FROM wccrm_anprobe
GROUP BY date , branch


But the output is just the days and the number of models, and not all date merged into months...



Best Regards,



Stefan







mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 17:24

























asked Nov 19 at 17:03









Bosstone

92110




92110








  • 1




    and what SQL have you tried thus far?
    – treyBake
    Nov 19 at 17:04






  • 2




    Question examples using images are bad i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 19 at 17:04








  • 1




    Hint: SELECT <some_columns>, COUNT(*) ... WHERE state = 1 GROUP BY <some_columns>.. Keep <some_columns> the same..
    – Raymond Nijland
    Nov 19 at 17:06
















  • 1




    and what SQL have you tried thus far?
    – treyBake
    Nov 19 at 17:04






  • 2




    Question examples using images are bad i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 19 at 17:04








  • 1




    Hint: SELECT <some_columns>, COUNT(*) ... WHERE state = 1 GROUP BY <some_columns>.. Keep <some_columns> the same..
    – Raymond Nijland
    Nov 19 at 17:06










1




1




and what SQL have you tried thus far?
– treyBake
Nov 19 at 17:04




and what SQL have you tried thus far?
– treyBake
Nov 19 at 17:04




2




2




Question examples using images are bad i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Raymond Nijland
Nov 19 at 17:04






Question examples using images are bad i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Raymond Nijland
Nov 19 at 17:04






1




1




Hint: SELECT <some_columns>, COUNT(*) ... WHERE state = 1 GROUP BY <some_columns>.. Keep <some_columns> the same..
– Raymond Nijland
Nov 19 at 17:06






Hint: SELECT <some_columns>, COUNT(*) ... WHERE state = 1 GROUP BY <some_columns>.. Keep <some_columns> the same..
– Raymond Nijland
Nov 19 at 17:06














1 Answer
1






active

oldest

votes

















up vote
0
down vote













Thank you for your suggestions. I have solved it that way:



SELECT count(*) as Anzahl, MONTHNAME( date ) AS Monat, YEAR( date ) AS Jahr, branch,     
ordered as Verkauf FROM wccrm_anprobe where status = 1 GROUP BY
MONTHNAME(date),YEAR(date), branch, ordered ORDER BY date,branch ASC


Best Regards,



Stefan






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379464%2fmysql-query-with-count-and-group-by%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Thank you for your suggestions. I have solved it that way:



    SELECT count(*) as Anzahl, MONTHNAME( date ) AS Monat, YEAR( date ) AS Jahr, branch,     
    ordered as Verkauf FROM wccrm_anprobe where status = 1 GROUP BY
    MONTHNAME(date),YEAR(date), branch, ordered ORDER BY date,branch ASC


    Best Regards,



    Stefan






    share|improve this answer

























      up vote
      0
      down vote













      Thank you for your suggestions. I have solved it that way:



      SELECT count(*) as Anzahl, MONTHNAME( date ) AS Monat, YEAR( date ) AS Jahr, branch,     
      ordered as Verkauf FROM wccrm_anprobe where status = 1 GROUP BY
      MONTHNAME(date),YEAR(date), branch, ordered ORDER BY date,branch ASC


      Best Regards,



      Stefan






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Thank you for your suggestions. I have solved it that way:



        SELECT count(*) as Anzahl, MONTHNAME( date ) AS Monat, YEAR( date ) AS Jahr, branch,     
        ordered as Verkauf FROM wccrm_anprobe where status = 1 GROUP BY
        MONTHNAME(date),YEAR(date), branch, ordered ORDER BY date,branch ASC


        Best Regards,



        Stefan






        share|improve this answer












        Thank you for your suggestions. I have solved it that way:



        SELECT count(*) as Anzahl, MONTHNAME( date ) AS Monat, YEAR( date ) AS Jahr, branch,     
        ordered as Verkauf FROM wccrm_anprobe where status = 1 GROUP BY
        MONTHNAME(date),YEAR(date), branch, ordered ORDER BY date,branch ASC


        Best Regards,



        Stefan







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 18:00









        Bosstone

        92110




        92110






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379464%2fmysql-query-with-count-and-group-by%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Tonle Sap (See)

            I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

            Guatemaltekische Davis-Cup-Mannschaft