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
]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
add a comment |
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
]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
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
add a comment |
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
]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
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
]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
mysql
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 19 at 18:00
Bosstone
92110
92110
add a comment |
add a comment |
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%2f53379464%2fmysql-query-with-count-and-group-by%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
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