the case function returns only the first qualifying value, and the remainder of the case is automatically ignored.
For example, the following SQL, you can never get the "second class" results
The code is as follows
Copy Code
Case when col_1 in (' A ', ' B ') THEN ' first class 'When Col_1 in (' a ') THEN ' Class II 'Else ' other ' end
Let's take a look at what we can do with the case function.
First, the known data is grouped and analyzed in a diff
a different way to group, analysis.There is the following data: (in order to see more clearly, I did not use the country code, but directly with the country name as primary Key)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
250
the country name as primary Key)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
According to the population data of this country, the p
' man ' when sex = ' 2 ' Then ' Women ' Else ' other ' ENDIn both of these ways, the same functionality can be achieved. The simple case function is relatively concise, but there are some limitations in function, such as write-judgement, compared to the search function.There is also a problem to be aware that the case function returns only the first qualifying value, and the remaining case section is automatically ignored.--for example, the following SQL, you can never get the result of a "seco
primary Key)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
According to the population data of this country, the population of Asia and
to see more clearly, I did not use the country code, but directly with the country name as primary Key)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
250
Germany
200
Mexico
50
India
)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
According to the population data of this country, the population of Asia and North America
, the known data is grouped in another way, analyzed. has the following data: (in order to see more clearly, I did not use the country code, but directly with the country name as primary Key)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
key)
country)
Population
China
600
USA
100
Canada
100
UK
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
The population of Asia and North America is counted based on the population data of this country. The following result is returned.
electronic devices
Transfer Rate (%)
√
√
√
First pass rate (%)
√
√
√
Manufacturing cost per unit ($)
√
×
√
Material Inventory days
×
√
√
And so on...
Looking at this table, Mo Miao frowned: "You can't waste any time organizing the data. You need to focus on analyzing and coping with the factory manufacturing work ."
Alan thought for a while and thought it was time to a
key)
country)
Population
China
600
USA
100
Canada
100
UK
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
The population of Asia and North America is counted based on the population data of this country. The following result is returned.
Expected results: (I got a one-to-one relationship and compared it to another table) Select * From empoylee where (address1, address2) in (select address1, address2from empoyleeadresseswhere Country = 'Canada ') the preceding method cannot be used. You can also select * from (select (zcbm |', '| fwbm), which is slow) as T from t_fwzc) TT where T not in (select (zcbm | ',' | fwbm) as C from t_zc_fc_gx) solution 1: Use exists to determine select. * From
as primary Key)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
According to the population data of this country, the population of Asia
directly with the country name as primary Key)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
According to the population data of this c
more clearly, I did not use the country code, but directly with the country name as primary Key)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
example, the following SQL, you can never get the "second class" this result The code is as follows Case is col_1 in (' A ', ' B ') then ' first Class ' When Col_1 in (' a ') then ' second class ' Else ' other ' END Let's take a look at what you can do with the case function. One, the known data in a different way to group, analysis. There is the following data: (in order to see more clearly, I did not use the country code, but directly with the country name as primary Key) Country (country) po
with the previous basis, I might be a little rough.
1. Each layer of the example of course to insert a layer, this example inserts a smiley face layer, but also inserts an implicit layer, in order to display under the place name, in this case the hidden layer content is some text graphics convenient. No way? Hidden layers are not inserted. is to insert a layer first, the floating property panel of the Vis item selected hidden can be
2. Pull up the time axis panel (CTRUL+F9), with the mouse to
country name as primary Key)
Country (country)
Population (population)
China
600
United States
100
Canada
100
United Kingdom
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
According to the population data of this country, the popu
country name as primary Key)
Country (countr Y)
Population (population)
China
600
United States
100
Canada
100
UK
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
According to the population data
country name as primary Key)
Country (countr Y)
Population (population)
China
600
United States
100
Canada
100
UK
200
France
300
Japan
250
Germany
200
Mexico
50
India
250
According to the population data
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.