Query Grouping statistics

Source: Internet
Author: User
CREATE TABLE TB
(
ID int,
name varchar (),
categorical int,
encoded int,
user ID int

) INSERT INTO
 
TB VALUES (1, ' A ', 1,1,1111)
insert into terabytes values (2, ' B ', 1,0,3333)
insert into TB values (3, ' C ', 2,0,3333)
INSERT into TB values (4, ' D ', 3,0,3333)
inserts into terabytes values (5, ' E ', 3,0,4444)
insert into TB values (6, ' F ',  3,0,4444)

 

 
 
SELECT user ID,

       sum (case when class = 1 and encoded = 0 Then 1 else 0 end) [Data of Category 1 encoded 0],
       sum (case when class = 1 and encoded = 1 then 1 else 0 end) [Data of Category 1 encoded 1],
       sum (case when class = 2 and encode = 0 Then 1 else 0 end) [Data of Category 2 encoded 0],
       sum ( case when class = 2 and encoded = 1 then 1 else 0 end) [Data of Category 2 coded 1],
       sum (case when class = 3 and encode = 0 Then 1 else 0 end) [Category 3 encoding 0 data],
       sum (case when class = 3 and encoded = 1 then 1 else 0 end) [Data of Category 3 encoded 1] from
TB
GROUP by User ID

SELECT user i D, from


TB
GROUP by User ID

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.