The table game_info is known as follows
Date_info |
Result_info |
2018-2-4 |
Win |
2018-2-4 |
Lose |
2018-2-4 |
Win |
2018-2-4 |
Lose |
2018-2-5 |
Lose |
2018-2-5 |
Lose |
2018-2-5 |
Lose |
Q. How do I find the following results?
Date_info |
Win |
Lose |
2018-2-4 |
2 |
2 |
2018-2-5 |
0 |
3 |
First CREATE TABLE game_infdate_info not NULL,
Result_info varchar (5) Check (Result_info in (' Win ', ' lose '));
Inserting data
INSERT into game_info values (' 2018-2-4 ', ' win '), (' 2018-2-5 ', ' lose ');
Query statements
As lose from Game_info Group by Date_info ORDER by date_info ASC;
This is to illustrate the use of the case when statement,
There are two ways to use case
Case Result_info if ' win ' then 1 else 0end
Another usage is
Case if result_info = ' win ' then 1 else 0end
Case-When statements are also commonly used when judging gender
As in the database of gender in the table is the number 1, 2, but want to query out male, female
Select (Case gender if 1 Then ' Male ' when 2 then ' Women 'Else ' Other ' end) As gender from
SQL Server's case when statement uses implementation statistics