Cross-Table Learning

Source: Internet
Author: User
Assume that there are four subjects in analyticdb.
Add a data entry for each subject

Create Table [DBO]. [score] (
[ID] [int] identity (1, 1) not null,
[Name] [varchar] (50) Collate chinese_prc_ci_as null,
[Subject] [varchar] (50) Collate chinese_prc_ci_as null,
[Score] [int] Null
) On [primary]

Let's take a look at this.
Declare @ A varchar (2000)
Set @ A =''
Select @ A = @ A + ',' + Cast (ID as varchar) from Score
Print @

Select name,
Sum (case subject when' then score else 0 end) as English,
Sum (case subject when 'physical 'Then score else 0 end) as physical,
Sum (case subject when 'mate' then score else 0 end) as mathematics,
Sum (case subject when 'Chemical' then score else 0 end) as chemistry
From score group by name

Note: When the field is placed after the when, multiple conditions can be judged.
Sum (case when subject <> 'English 'Then score else 0 end) as not English,

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.