How to summarize data in sql? -


i have table of data , need extract count of value on report table on excel, need show rows , columns in report.

my table looks like:

id  val  sets 1   aa   25 2   aa   26 3   bb   25 4   cc   27 5   aa   27 6   aa   25 

and report in format:

    25  26  27 aa  2   1   1 bb  1   0   0 cc  0   0   1 

with conditional aggregation:

select val,        sum(case when sets = 25 1 else 0 end) [25],        sum(case when sets = 26 1 else 0 end) [26],        sum(case when sets = 27 1 else 0 end) [27] tablename group val 

with pivoting:

select val,        [25],        [26],        [27] tablename pivot(count(id) sets in([25],[26],[27]))p 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -