SQL: Finding the total number of items for each category and ordering the resultWhat is the best way to paginate results in SQL ServerSQL to find the number of distinct values in a columnHow do I limit the number of rows returned by an Oracle query after ordering?SQL multiple column orderingFinding duplicate values in a SQL tableFind all tables containing column with specified name - MS SQL ServerFind duplicate lines in a file and count how many time each line was duplicated?Database design for products with multiple categories and multiple sub-featuresMySQL: Sort items by category countSQL: Counting the total number of distinct items within a category
Write The Shortest Program to Calculate Height of a Binary Tree
Is it okay to use different fingers every time while playing a song on keyboard? Is it considered a bad practice?
Repeated! Factorials!
Vectorised way to calculate mean of left and right neighbours in a vector
Can you put ranks into knowledge skills that aren't class skills?
Why do rocket engines use nitrogen actuators to operate the fuel/oxidiser valves instead of electric servos?
Is an "are" omitted in this sentence
Has J.J.Jameson ever found out that Peter Parker is Spider-Man?
split inside flalign
Why is the Vasa Museum in Stockholm so Popular?
How do people drown while wearing a life jacket?
Is it uncompelling to continue the story with lower stakes?
How do I show and not tell a backstory?
Need reasons why a satellite network would not work
Did Logical Positivism fail because it simply denied human emotion?
How to check a file was encrypted (really & correctly)
Why did the US Airways Flight 1549 passengers stay on the wings?
Is there a general term for the items in a directory?
Variable doesn't parse as string
Formal mathematical definition of renormalization group flow
Is there a way to improve my grade after graduation?
How do the surviving Asgardians get to Earth?
What do "unsettled funds" mean?
Pronouns when writing from the point of view of a robot
SQL: Finding the total number of items for each category and ordering the result
What is the best way to paginate results in SQL ServerSQL to find the number of distinct values in a columnHow do I limit the number of rows returned by an Oracle query after ordering?SQL multiple column orderingFinding duplicate values in a SQL tableFind all tables containing column with specified name - MS SQL ServerFind duplicate lines in a file and count how many time each line was duplicated?Database design for products with multiple categories and multiple sub-featuresMySQL: Sort items by category countSQL: Counting the total number of distinct items within a category
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have the following table called Field:
Category | Industry | Company
Research Science Biolite
Retail Healthcare The Vitamin Shop
Crafts Stationery Art Centre
Research Science GeneSys
Retail Healthcare Live Healthy
Crafts Stationery Typewrite Pens
I want to be able to find the total number of companies per industry, and then order the result by Category and then Industry. (E.g. for Science there would be 2 companies, for Healthcare there would be 2 companies and for Stationery there would be 2 companies as well). The output should look like this (unordered):
Category | Industry | Number
Research Science 2
Retail Healthcare 2
Crafts Stationery 2
I have the following query:
select t1.Category, t1.Industry, t2.Number from Field t1
inner join (
select Industry, count(*) as Number from Field
group by Industry
) t2
on t1.Industry = t2.Industry;
However, in the resulting table, in the Industry column, duplicate industries are shown (e.g. Science shows up twice). How can I get the Industry column to show each industry only once?
mysql sql count
add a comment |
I have the following table called Field:
Category | Industry | Company
Research Science Biolite
Retail Healthcare The Vitamin Shop
Crafts Stationery Art Centre
Research Science GeneSys
Retail Healthcare Live Healthy
Crafts Stationery Typewrite Pens
I want to be able to find the total number of companies per industry, and then order the result by Category and then Industry. (E.g. for Science there would be 2 companies, for Healthcare there would be 2 companies and for Stationery there would be 2 companies as well). The output should look like this (unordered):
Category | Industry | Number
Research Science 2
Retail Healthcare 2
Crafts Stationery 2
I have the following query:
select t1.Category, t1.Industry, t2.Number from Field t1
inner join (
select Industry, count(*) as Number from Field
group by Industry
) t2
on t1.Industry = t2.Industry;
However, in the resulting table, in the Industry column, duplicate industries are shown (e.g. Science shows up twice). How can I get the Industry column to show each industry only once?
mysql sql count
add a comment |
I have the following table called Field:
Category | Industry | Company
Research Science Biolite
Retail Healthcare The Vitamin Shop
Crafts Stationery Art Centre
Research Science GeneSys
Retail Healthcare Live Healthy
Crafts Stationery Typewrite Pens
I want to be able to find the total number of companies per industry, and then order the result by Category and then Industry. (E.g. for Science there would be 2 companies, for Healthcare there would be 2 companies and for Stationery there would be 2 companies as well). The output should look like this (unordered):
Category | Industry | Number
Research Science 2
Retail Healthcare 2
Crafts Stationery 2
I have the following query:
select t1.Category, t1.Industry, t2.Number from Field t1
inner join (
select Industry, count(*) as Number from Field
group by Industry
) t2
on t1.Industry = t2.Industry;
However, in the resulting table, in the Industry column, duplicate industries are shown (e.g. Science shows up twice). How can I get the Industry column to show each industry only once?
mysql sql count
I have the following table called Field:
Category | Industry | Company
Research Science Biolite
Retail Healthcare The Vitamin Shop
Crafts Stationery Art Centre
Research Science GeneSys
Retail Healthcare Live Healthy
Crafts Stationery Typewrite Pens
I want to be able to find the total number of companies per industry, and then order the result by Category and then Industry. (E.g. for Science there would be 2 companies, for Healthcare there would be 2 companies and for Stationery there would be 2 companies as well). The output should look like this (unordered):
Category | Industry | Number
Research Science 2
Retail Healthcare 2
Crafts Stationery 2
I have the following query:
select t1.Category, t1.Industry, t2.Number from Field t1
inner join (
select Industry, count(*) as Number from Field
group by Industry
) t2
on t1.Industry = t2.Industry;
However, in the resulting table, in the Industry column, duplicate industries are shown (e.g. Science shows up twice). How can I get the Industry column to show each industry only once?
mysql sql count
mysql sql count
asked Mar 27 at 2:49
ceno980ceno980
6902 silver badges6 bronze badges
6902 silver badges6 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Grouping by both Category and Industry:
select Category,Industry, count(*) as 'Number'
from Field
group by Category,Industry
SQLFiddle for this answer
– esqew
Mar 27 at 2:59
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%2f55369066%2fsql-finding-the-total-number-of-items-for-each-category-and-ordering-the-result%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
Grouping by both Category and Industry:
select Category,Industry, count(*) as 'Number'
from Field
group by Category,Industry
SQLFiddle for this answer
– esqew
Mar 27 at 2:59
add a comment |
Grouping by both Category and Industry:
select Category,Industry, count(*) as 'Number'
from Field
group by Category,Industry
SQLFiddle for this answer
– esqew
Mar 27 at 2:59
add a comment |
Grouping by both Category and Industry:
select Category,Industry, count(*) as 'Number'
from Field
group by Category,Industry
Grouping by both Category and Industry:
select Category,Industry, count(*) as 'Number'
from Field
group by Category,Industry
answered Mar 27 at 2:57
danblackdanblack
3,5381 gold badge4 silver badges22 bronze badges
3,5381 gold badge4 silver badges22 bronze badges
SQLFiddle for this answer
– esqew
Mar 27 at 2:59
add a comment |
SQLFiddle for this answer
– esqew
Mar 27 at 2:59
SQLFiddle for this answer
– esqew
Mar 27 at 2:59
SQLFiddle for this answer
– esqew
Mar 27 at 2:59
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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.
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%2f55369066%2fsql-finding-the-total-number-of-items-for-each-category-and-ordering-the-result%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