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
sql-server
New contributor
add a comment |
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
sql-server
New contributor
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
add a comment |
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
sql-server
New contributor
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
sql-server
New contributor
New contributor
edited Nov 17 at 22:46
New contributor
asked Nov 17 at 21:51
josh_00
33
33
New contributor
New contributor
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 17 at 23:57
Used_By_Already
21.6k21838
21.6k21838
add a comment |
add a comment |
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.
josh_00 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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