I have two tables as follows:
table1
id | fullname | gender | level
------------------------------
1 | Jerry | Male | Year 1
2 | Jen | Female | Year 1
3 | Tom | Male | Year 2
4 | Natasha | Female | Year 2
table2
level | male | female
----------------------
| |
| |
What I want to do is to INSERT the total no. of male and total no. of female from table1 into table2 group by the level.
The expected result supposed to look like the following table:
level | male | female
---------------------
Year 1 | 1 | 1
Year 2 | 1 | 1
I've tried the following code:
INSERT INTO table2 (level, male, female)
SELECT level,
SUM(gender = 'Male') male,
SUM(gender = 'Female') female,
FROM table1
GROUP BY level
The above code I got it from one of the question asked here as it seemed to have the same problems as mine BUT when I run the code, it doesn't give me anything.
Is the problem from the tables itself? Or is it from the code?
female. I consider this a typographic error and vote to close such questions.