This interview is very special, gave the test paper, let the direct oral answer, to tell the truth, quite like this.
The last is a database problem, the table is as follows
I yy the initialization statement
Mysql> CREATE TABLE Fmatch (mdate date, Team varchar, res enum (' WIN ', ' lose '));mysql> insert into fmatch values (' 2 010-10-19 ', ' 76ers ', ' WIN '); Query OK, 1 row affected (0.07 sec) mysql> insert into fmatch values (' 2010-10-20 ', ' 76ers ', ' lose '); Query OK, 1 row affected (0.07 sec) mysql> insert into fmatch values (' 2010-10-20 ', ' NET ', ' WIN '); Query OK, 1 row affected (0.04 sec) mysql> insert into fmatch values (' 2010-10-21 ', ' NET ', ' WIN '); Query OK, 1 row affected (0.04 sec)
Here are the questions
1. Identify the earliest day and last day data
That
Idea: Max, min
Answer:
SELECT * from Fmatch where mdate in (select Max (mdate) from Fmatch) or mdate in (select min (mdate) from Fmatch);
This question is relatively simple, but if you have a better answer, welcome to share!
The second question is more difficult.
2. Statistics on the outcome of each team
I didn't think of it on the spot. An SQL statement does not solve the problem if you want to use the IF statement. Oh, that's so stupid.
Back on the internet to find out a very close answer
Select A.team, A.win,b.lose from (SELECT COUNT (*) win, team from Fmatch where res= ' win ' Group by team) a left join (s Elect Count (*) lose, team from Fmatch where res= ' lose ' GROUP by team] B on A.team=b.team;
There are still flaws, however, when the data is not displayed as Null instead of 0.
There is the interview when the interviewer gave the hint is the ranks of the transformation, really need to use the ranks of the transformation??
How to solve??? Help you netizens!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Database face test--match data query