Applying the same idea to our TA_CASES table, we could add a COUNT of supplied CITIZENSHIPS, because it has its own column, unrelated to the FEE_NUMBERs. For example, a crosstab that shows the SUM of lawnmowers and garden hose sales for a collection of retail stores could be easily produced in this way, since the sales of each product would presumably be stored in different columns. In many instances, it is simple enough to add more fields to a crosstab query, by aggregating on different table columns. We’ll be getting to that once we’ve dealt with a few more scenarios relating to predefined columns. Generating results based on a variable number of columns is also possible, but it requires writing a stored procedure. Moreover, we will see how the efficacy of the CASE statement within an aggregate function decreases in direct proportion to the complexity of the criteria.Īs in the previous articles on the crosstab query, we’ll be limiting the scope to queries where the number of possible values in the column axis is known beforehand. As we will see, inserting additional columns to a crosstab query is less straightforward than adding row data, the reason being that SQL naturally groups data by rows. This article is a continuation of Multi-Aggregated Rows in Crosstab Queries. Today’s topic is crosstabs, which contain multiple aggregate functions in the column axis. Moreover, the efficacy of the CASE statement within an aggregate function decreases in direct proportion to the complexity of the criteria. Inserting additional columns to a crosstab query is less straightforward than adding row data, because SQL naturally groups data by rows.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |