One 、 Data preparation
Here's the data , Student id, Course , fraction
1,yuwen,43
1,shuxue,55
2,yuwen,77
2,shuxue,88
3,yuwen,98
3,shuxue,65
Two 、 Demand analysis
1、 Create table
create table requirement( sid int, course string, score int)row format delimited fields terminated by ',';
2、 Upload data
load data local inpath '/usr/mydir/data/requirement.txt' into table requirement;
3、 Verify that the data is correct
select * from requirement;
4、 Query data
Method 1 :
select sid, max(math) as math, max(chinese) as chinese from (select *, case course when 'shuxue' then score else 0 end .........