sql row after row transfer analysis no longer have to remember the

 

Table scores

 

Please turn into a cross-table is like this:

 

//

:::: Our next analyzed: First Name this column must be distinct name [repeat there is no way this demand can only be the case] so we use group by [Name] and then the name of this column will have three other column is the need to scrape it up! ! ! ! We remember. Aggregate functions is the only one! ! ! This feature is just being used. Hey we use aggregate functions can sum it max min These are not all right! ! !

To repeat here for [name] regardless of Ha otherwise I think this seems to have problems! ! !

 

select name,
SUM (Case curriculum when 'language' then scores else 0 end) as language,
SUM (Case curriculum when 'mathematics' then scores else 0 end) as mathematics,
SUM (Case curriculum when 'physical' then scores else 0 end ) as a physical
from scores group by name


- extending select id, max (case when saleBill = 222 then 222 end) from ChuKuBill group by id there is no else else the default to null 

 

::: cross should turn table becomes the table above a one of how to do it? We analyzed a list of only three pairs now! ! The effect is equivalent to [Joe Smith + + language scores; Joe Smith + + math scores. . [John Doe] + + + language scores; John Doe + + math scores. . ] A folded piece of a situation: we have a union and union all union would solve the difference is that here we do not let it go heavy to heavy weight does not matter to Kazakhstan [two] can not all be the same

Header Header is not present us with AS alias out the overall look is down select names under analysis, the 'language' as curriculum, language as the score right! ! Joe Smith came out to do the same language scores in math John's last joint of John Doe 

 

select name,
'language' as curriculum,
language as scores
from scores2
of Union All
select name,
'mathematics' as curriculum,
mathematics as scores
from scores2
of Union All
select name,
'physical' as curriculum,
physical as scores
from scores2
the Order by name desc [2019.10.28] that there is a problem

answer;

select name,
SUM (Case curriculum when 'language' then scores else 0 end) as language,
SUM (Case curriculum when 'mathematics' then scores else 0 end) as mathematics,
SUM (Case curriculum when 'physical' then scores else 0 end ) as physical

---------------------

Guess you like

Origin www.cnblogs.com/bawang/p/11338693.html
Row