Waiting to be written ~
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 >
fsalary>9999 and Fage <
fsalary <9999 and Fage >
fsalary <9999 and Fage <
the number of employees per type;
Select sum (case when fsalary > 9999 and Fage >
Then 1
else 0end) as "fsalary>9999_fage>35",
sum (case when fsalary > 9999 and Fage <
Then 1
Else 0
end) as "fsalary>9999_fage<35",
sum (case when Fsalary < 9999 and Fage >
Then 1
Else 0
end) as "fsalary<9999_fage>35",
sum (case when Fsalary < 9999 and Fage <
Then 1
Else 0
end) as "fsalary<9999_fage<35"
From Empinfo;
1 SELECT 2 Case -------------If3 whenSex='1' Then 'male' -------------sex= ' 1 ', the return value ' male '4 whenSex='2' Then 'female' -------------sex= ' 2 ', the return value ' female '5 Else 0 -------------Other return ' other '6 End -------------End7 fromSys_user--------Overall Understanding: In the Sys_user table if sex= ' 1 ', then the return value ' male ' if sex= ' 2 ', then return the value ' female ' otherwise return ' other '
1 SELECT 2 Case -------------If3 whenSex='1' Then 'male' -------------sex= ' 1 ', the return value ' male '4 whenSex='2' Then 'female' -------------sex= ' 2 ', the return value ' female '5 Else 0 -------------Other return ' other '6 End -------------End7 fromSys_user--------Overall Understanding: In the Sys_user table if sex= ' 1 ', then the return value ' male ' if sex= ' 2 ', then return the value ' female ' otherwise return ' other '
View Code
MySQL Learning notes