Distinct/unique count nested in aggregation











up vote
0
down vote

favorite












I'm trying to alter a table, create a distinct count column and group by week.
Any Ideas? I'm not sure how to wrap in multiple aggregations?



Here is the table and desired result



Here are before and after tables












share|improve this question









New contributor




josh_00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • I don't have more data to input - is that what you're asking for?
    – josh_00
    Nov 17 at 22:19










  • If I wrote a really nice but long solution query, took a screenshot of it, and added that image as an answer, would you be annoyed about the transcription effort? Please don't use images of data, just copy/paste some data into the question and format it using the {} button in the toolbar. ps: You can use ozh.github.io/ascii-tables to create ascii tables.
    – Used_By_Already
    Nov 17 at 23:52










  • that helps, thank you
    – josh_00
    Nov 18 at 0:36










  • no problem. For future questions: please don't use images of data >> very frustrating
    – Used_By_Already
    Nov 18 at 0:36

















up vote
0
down vote

favorite












I'm trying to alter a table, create a distinct count column and group by week.
Any Ideas? I'm not sure how to wrap in multiple aggregations?



Here is the table and desired result



Here are before and after tables












share|improve this question









New contributor




josh_00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • I don't have more data to input - is that what you're asking for?
    – josh_00
    Nov 17 at 22:19










  • If I wrote a really nice but long solution query, took a screenshot of it, and added that image as an answer, would you be annoyed about the transcription effort? Please don't use images of data, just copy/paste some data into the question and format it using the {} button in the toolbar. ps: You can use ozh.github.io/ascii-tables to create ascii tables.
    – Used_By_Already
    Nov 17 at 23:52










  • that helps, thank you
    – josh_00
    Nov 18 at 0:36










  • no problem. For future questions: please don't use images of data >> very frustrating
    – Used_By_Already
    Nov 18 at 0:36















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to alter a table, create a distinct count column and group by week.
Any Ideas? I'm not sure how to wrap in multiple aggregations?



Here is the table and desired result



Here are before and after tables












share|improve this question









New contributor




josh_00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm trying to alter a table, create a distinct count column and group by week.
Any Ideas? I'm not sure how to wrap in multiple aggregations?



Here is the table and desired result



Here are before and after tables









sql-server






share|improve this question









New contributor




josh_00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




josh_00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 17 at 22:46





















New contributor




josh_00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 17 at 21:51









josh_00

33




33




New contributor




josh_00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





josh_00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






josh_00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • I don't have more data to input - is that what you're asking for?
    – josh_00
    Nov 17 at 22:19










  • If I wrote a really nice but long solution query, took a screenshot of it, and added that image as an answer, would you be annoyed about the transcription effort? Please don't use images of data, just copy/paste some data into the question and format it using the {} button in the toolbar. ps: You can use ozh.github.io/ascii-tables to create ascii tables.
    – Used_By_Already
    Nov 17 at 23:52










  • that helps, thank you
    – josh_00
    Nov 18 at 0:36










  • no problem. For future questions: please don't use images of data >> very frustrating
    – Used_By_Already
    Nov 18 at 0:36




















  • I don't have more data to input - is that what you're asking for?
    – josh_00
    Nov 17 at 22:19










  • If I wrote a really nice but long solution query, took a screenshot of it, and added that image as an answer, would you be annoyed about the transcription effort? Please don't use images of data, just copy/paste some data into the question and format it using the {} button in the toolbar. ps: You can use ozh.github.io/ascii-tables to create ascii tables.
    – Used_By_Already
    Nov 17 at 23:52










  • that helps, thank you
    – josh_00
    Nov 18 at 0:36










  • no problem. For future questions: please don't use images of data >> very frustrating
    – Used_By_Already
    Nov 18 at 0:36


















I don't have more data to input - is that what you're asking for?
– josh_00
Nov 17 at 22:19




I don't have more data to input - is that what you're asking for?
– josh_00
Nov 17 at 22:19












If I wrote a really nice but long solution query, took a screenshot of it, and added that image as an answer, would you be annoyed about the transcription effort? Please don't use images of data, just copy/paste some data into the question and format it using the {} button in the toolbar. ps: You can use ozh.github.io/ascii-tables to create ascii tables.
– Used_By_Already
Nov 17 at 23:52




If I wrote a really nice but long solution query, took a screenshot of it, and added that image as an answer, would you be annoyed about the transcription effort? Please don't use images of data, just copy/paste some data into the question and format it using the {} button in the toolbar. ps: You can use ozh.github.io/ascii-tables to create ascii tables.
– Used_By_Already
Nov 17 at 23:52












that helps, thank you
– josh_00
Nov 18 at 0:36




that helps, thank you
– josh_00
Nov 18 at 0:36












no problem. For future questions: please don't use images of data >> very frustrating
– Used_By_Already
Nov 18 at 0:36






no problem. For future questions: please don't use images of data >> very frustrating
– Used_By_Already
Nov 18 at 0:36














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










COUNT(distinct ...) in a simple grouping query should work I believe



select week, theater, count(distinct person) as uniq_person
from yourtable
group by week, theater





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
    });


    }
    });






    josh_00 is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355890%2fdistinct-unique-count-nested-in-aggregation%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
    1
    down vote



    accepted










    COUNT(distinct ...) in a simple grouping query should work I believe



    select week, theater, count(distinct person) as uniq_person
    from yourtable
    group by week, theater





    share|improve this answer

























      up vote
      1
      down vote



      accepted










      COUNT(distinct ...) in a simple grouping query should work I believe



      select week, theater, count(distinct person) as uniq_person
      from yourtable
      group by week, theater





      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        COUNT(distinct ...) in a simple grouping query should work I believe



        select week, theater, count(distinct person) as uniq_person
        from yourtable
        group by week, theater





        share|improve this answer












        COUNT(distinct ...) in a simple grouping query should work I believe



        select week, theater, count(distinct person) as uniq_person
        from yourtable
        group by week, theater






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 at 23:57









        Used_By_Already

        21.6k21838




        21.6k21838






















            josh_00 is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            josh_00 is a new contributor. Be nice, and check out our Code of Conduct.













            josh_00 is a new contributor. Be nice, and check out our Code of Conduct.












            josh_00 is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355890%2fdistinct-unique-count-nested-in-aggregation%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

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]