Explain:
SELECT
Case-------------If
When the sex= ' 1 ' then ' Male '-------------sex= ' 1 ', the return value ' male '
When the sex= ' 2 ' then ' female '-------------sex= ' 2 ', the return value ' female '
else 0 return ' other '-------------other
End-------------Ended
From Sys_user--------Overall understanding: In the Sys_user table if sex= ' 1 ', then return the value ' male ' if sex= ' 2 ', then return the value ' female ' otherwise return ' other '
---usage one:
SELECT
Case is state = ' 1 ' Then ' success '
When state = ' 2 ' Then ' failed '
Else ' other ' END
From Sys_scheduler
---Usage II:
SELECT State
Case "1 ' Then ' success '
When ' 2 ' then ' failed '
Else ' other ' END
From Sys_scheduler
Liezi:
have employee table Empinfo
(
Fempno VARCHAR2 (TEN) NOT NULL PK,
Fempname varchar2 () NOT NULL,
FAGE number is not NULL,
Fsalary number NOT NULL
);
If the amount of data is about 10 million; write a SQL that you think is most efficient, and use a SQL to calculate the following four types of people:
fsalary>9999 and Fage > 35
fsalary>9999 and Fage < 35
Fsalary <9999 and Fage > 35
Fsalary <9999 and Fage < 35
The number of employees per type;
Select sum (case when fsalary > 9999 and Fage > 35
Then 1
else 0end) as "fsalary>9999_fage>35",
SUM (case when fsalary > 9999 and Fage < 35
Then 1
else 0
End) as "fsalary>9999_fage<35",
SUM (case when Fsalary < 9999 and Fage > 35
Then 1
else 0
End) as "fsalary<9999_fage>35",
SUM (case when Fsalary < 9999 and Fage < 35
Then 1
else 0
End) as "fsalary<9999_fage<35"
From Empinfo;
The use of case-then-else end in MYSQL