How to create two consecutive Group By in SQL [closed] - mysql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have this kind of code
SELECT MONTH(date_entered) AS Month,sex, COUNT(*) AS Customer
FROM customer
GROUP BY month
ORDER BY Month
I want to split sex (M and F) for each month. But the result that I get combine both sex

You need to include sex in group by as well
SELECT
MONTH(date_entered) AS Month,
sex,
COUNT(*) AS Customer
FROM customer
GROUP BY
MONTH(date_entered),
sex
ORDER BY
Month

Related

How do I count an instance based on 2 conditions that need to be met? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I created a schema in MySQL workbench & a table named: "exam"
The table has column names: "Exam_ID", "Start_Time", "Finish_Time", & "Room_ID"
I want to count all the exams that start after 5pm corresponding to each room.
SELECT COUNT(`Start_Time`) FROM `exam` WHERE `Start_Time`> '17:00:00' AND `Room_ID` = 'IR1';
SELECT COUNT(`Start_Time`) FROM `exam` WHERE `Start_Time`> '17:00:00' AND `Room_ID` = 'IR2';
SELECT COUNT(`Start_Time`) FROM `exam` WHERE `Start_Time`> '17:00:00' AND `Room_ID` = 'IR2';
Here is a sample of what I desire the output to look like
How can I count the # of exams correctly based on the conditions
This looks like filtering and aggregation:
select room_id, count(*) as cnt
from exam
where start_time > '17:00:00'
group by room_id

I want to show each product with the sum(total) quantity Which they sold out [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
i have table like this
date , N°ProDUCT , QUANTIE_SELL
every day i sell pruduct
N°pruduct------quantite_sell
i want to show eatch pruduct with the sum of the quantite ?
exmpl :1----82
2-----70
3-----12
the sql statment ??
Write the below query :-
SELECT SUM(quantite_sell) from product GROUP BY Nprod;
Thanks

How to calculate average in mysql with where clause [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Below is my database table.
what will be the sql query to calculate average score of all topic1 entries,of all topic2 entries and so on with where clause(where event_date between this to this)?
use group by
select topic_name, avg(score)
from my_table
where event_date between '2016-03-01' AND '2016-03-31'
group by topic_name

Statistics customer list with a total purchase value is greater than 50M in 3 months from the time of 31/1 and earlier [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have table orders(id, buyerEmail, paymentTime, finalPrice)
Mysql query to list customers purchase worth more than 50 million in the previous 3 months from 31.01.2014?
SELECT buyerEmail
FROM orders
WHERE paymentTime BETWEEN '2014-01-31' - INTERVAL 3 MONTH AND '2014-01-31'
GROUP BY buyerEmail
HAVING SUM(finalPrice) > 50000000

Show Month with the Highest Quantity Sold [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to show the month with the highest number of quantity sold.
I don't know how to do that. Please help thank you.
I have:
id, prod_name, price, q_sold, month
the q_sold must sum up with the number of month input.
You can order your result by the sum and take only the first entry with limit 1
select `month`, sum(q_sold) as sold_sum
from your_table
group by `month`
order by sold_sum desc
limit 1