![]() ![]() For each team this will show the number of games they've won, drawn, and lost.įirst, compare the home and away team points to find out whether each won, lost or drew. The output from the first becomes the input to the second.įor example, say you want to produce a league table from the match results. You can combine pivot and unpivot a single statement. This makes it easy to select and manipulate the columns you want. This and pivot's implicit grouping means it's a good idea to pivot the output of a CTE. Often you want to change values in the columns you're pivoting on. Select to_char ( match_date, 'MON' ) match_month Alias the expression and use this alias in the pivot. To fix this, extract the month in an inline view or CTE. You can extract a month's abbreviation from a date using to_char with the format mask 'MON'.īut if you do this in your pivot clause, you'll get an error: with rws as (Ĭount (*) for to_char ( match_date, 'MON' ) in ( So you need to convert the match dates to months. For example, you may want to see the number of games played each month, showing the months as columns. Sometimes you may want to manipulate the values you're pivoting by.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |