For mysql/hive to be counted, you can use a function if you want rows to become columns.
Case field A When value B then C [if D then e]* [ELSE F] END
When the field a= value B, return C (if the field is the value of the field, it can be a fixed value plus single quotation marks), when A=d, return E, otherwise return F.
Such as:
Data table structure: (for example, ID has duplicates)
Select Id,sum (case action is ' article ' then count else 0 end) as Article,sum (case action is ' user_comment ' then count else 0 end) as user_comment, sum (case action "profile" then count else 0 end) as ' profile ', sum (case action when ' user _follow ' then count else 0 end] as User_follow, sum (case action if ' user_repost ' then count else 0 end) as User_repost, SUM (case action, ' user_timeline ' then count else 0 end) as User_timeline from T_stat_user_action where Stat_time= ' 2015 0725 ' and id= ' 1820485935 ' GROUP by ID
Result is
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MySQL or hive data rows become columns