SQL query to count data from two columns (combined) of the table
Is there any SQL query which counts the total number of data combined from two or three columns and displays the total?
For example in the given table, column A has 1 and Column B has 2 so the result of the query should be:
and what could be SQL query if column A and B are common(repeating) but C has distinct data? Result should be:
mysql sql excel database
add a comment |
Is there any SQL query which counts the total number of data combined from two or three columns and displays the total?
For example in the given table, column A has 1 and Column B has 2 so the result of the query should be:
and what could be SQL query if column A and B are common(repeating) but C has distinct data? Result should be:
mysql sql excel database
add a comment |
Is there any SQL query which counts the total number of data combined from two or three columns and displays the total?
For example in the given table, column A has 1 and Column B has 2 so the result of the query should be:
and what could be SQL query if column A and B are common(repeating) but C has distinct data? Result should be:
mysql sql excel database
Is there any SQL query which counts the total number of data combined from two or three columns and displays the total?
For example in the given table, column A has 1 and Column B has 2 so the result of the query should be:
and what could be SQL query if column A and B are common(repeating) but C has distinct data? Result should be:
mysql sql excel database
mysql sql excel database
edited Nov 21 at 4:03
asked Nov 21 at 0:27
Krin
13
13
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Grouping on A,B and counting the results:
SELECT A,B, COUNT(*) as Total
FROM table
GROUP BY A,B
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:05
If C is distinct, which row should be selected?
– danblack
Nov 21 at 4:11
So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
– Krin
Nov 21 at 4:21
Append C to theGROUP BY
list and to theSELECT
results.
– danblack
Nov 21 at 4:24
1
@Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
Nov 21 at 5:02
|
show 1 more comment
select A, B, count(*)
from TABLE
group by A, B
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:04
add a comment |
SELECT
A
, B
, COUNT(*)
, COUNT(DISTINCT C)
FROM
table
GROUP BY
A
, B
Thanks worked well with what I was expecting.
– Krin
Nov 21 at 15:08
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f53403629%2fsql-query-to-count-data-from-two-columns-combined-of-the-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Grouping on A,B and counting the results:
SELECT A,B, COUNT(*) as Total
FROM table
GROUP BY A,B
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:05
If C is distinct, which row should be selected?
– danblack
Nov 21 at 4:11
So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
– Krin
Nov 21 at 4:21
Append C to theGROUP BY
list and to theSELECT
results.
– danblack
Nov 21 at 4:24
1
@Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
Nov 21 at 5:02
|
show 1 more comment
Grouping on A,B and counting the results:
SELECT A,B, COUNT(*) as Total
FROM table
GROUP BY A,B
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:05
If C is distinct, which row should be selected?
– danblack
Nov 21 at 4:11
So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
– Krin
Nov 21 at 4:21
Append C to theGROUP BY
list and to theSELECT
results.
– danblack
Nov 21 at 4:24
1
@Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
Nov 21 at 5:02
|
show 1 more comment
Grouping on A,B and counting the results:
SELECT A,B, COUNT(*) as Total
FROM table
GROUP BY A,B
Grouping on A,B and counting the results:
SELECT A,B, COUNT(*) as Total
FROM table
GROUP BY A,B
answered Nov 21 at 0:48
danblack
1,5071214
1,5071214
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:05
If C is distinct, which row should be selected?
– danblack
Nov 21 at 4:11
So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
– Krin
Nov 21 at 4:21
Append C to theGROUP BY
list and to theSELECT
results.
– danblack
Nov 21 at 4:24
1
@Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
Nov 21 at 5:02
|
show 1 more comment
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:05
If C is distinct, which row should be selected?
– danblack
Nov 21 at 4:11
So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
– Krin
Nov 21 at 4:21
Append C to theGROUP BY
list and to theSELECT
results.
– danblack
Nov 21 at 4:24
1
@Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
Nov 21 at 5:02
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:05
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:05
If C is distinct, which row should be selected?
– danblack
Nov 21 at 4:11
If C is distinct, which row should be selected?
– danblack
Nov 21 at 4:11
So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
– Krin
Nov 21 at 4:21
So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
– Krin
Nov 21 at 4:21
Append C to the
GROUP BY
list and to the SELECT
results.– danblack
Nov 21 at 4:24
Append C to the
GROUP BY
list and to the SELECT
results.– danblack
Nov 21 at 4:24
1
1
@Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
Nov 21 at 5:02
@Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
Nov 21 at 5:02
|
show 1 more comment
select A, B, count(*)
from TABLE
group by A, B
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:04
add a comment |
select A, B, count(*)
from TABLE
group by A, B
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:04
add a comment |
select A, B, count(*)
from TABLE
group by A, B
select A, B, count(*)
from TABLE
group by A, B
answered Nov 21 at 0:49
Michal Rosa
1,3061814
1,3061814
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:04
add a comment |
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:04
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:04
Updated the question, if you can help me with that. Thanks.
– Krin
Nov 21 at 4:04
add a comment |
SELECT
A
, B
, COUNT(*)
, COUNT(DISTINCT C)
FROM
table
GROUP BY
A
, B
Thanks worked well with what I was expecting.
– Krin
Nov 21 at 15:08
add a comment |
SELECT
A
, B
, COUNT(*)
, COUNT(DISTINCT C)
FROM
table
GROUP BY
A
, B
Thanks worked well with what I was expecting.
– Krin
Nov 21 at 15:08
add a comment |
SELECT
A
, B
, COUNT(*)
, COUNT(DISTINCT C)
FROM
table
GROUP BY
A
, B
SELECT
A
, B
, COUNT(*)
, COUNT(DISTINCT C)
FROM
table
GROUP BY
A
, B
answered Nov 21 at 4:22
fifonik
38518
38518
Thanks worked well with what I was expecting.
– Krin
Nov 21 at 15:08
add a comment |
Thanks worked well with what I was expecting.
– Krin
Nov 21 at 15:08
Thanks worked well with what I was expecting.
– Krin
Nov 21 at 15:08
Thanks worked well with what I was expecting.
– Krin
Nov 21 at 15:08
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53403629%2fsql-query-to-count-data-from-two-columns-combined-of-the-table%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