Use the decode function for Statistics

Source: Internet
Author: User

From the last week, we started to make statistical charts. Various statistical charts. The statistics made yesterday are as follows:

TYPE type_wlzh (), czdwdm (), accountSum (), jpAccountSum (), yxAccountSum (), wxAccountSum ())

Then create a Function. In the creation of this function, four connections need to be processed.

1. The leftmost part is the most fundamental statistical element: the work platform and organization. ,

 t.gzmb,t.czdwdm   t.gzmb,t.czdwdm

2. Calculate field C and union it to the previous part.

( t.gzmb,t.czdwdm   t.gzmb,t.czdwdm ,() jpAccountSum  t.account_lx     wlzh.gzmb  jpsl.gzmb  wlzh.czdwdm  jpsl.czdwdm

3. Duplicate field B and field C

4. In the last loop, assign the value to the new type and return the type.

Are you dizzy when you see this process? No matter whether you are dizzy or not, I am dizzy. While I was wondering where I could find a better solution, when Boss Chen (Department Technical Director) passed by me and when I had more functions, ask me how to write such a complex function, so I will give it to him, and people will directly drop a sentence: relying on it, it's so simple that you have to use the function and eat too much. So I knocked it up and completed it in less than a minute. The results were all what I wanted.

 t.gzmb,t.czdwdm ,((decode(t.account_lx,,,(decode(t.accountisyx,,,  t.gzmb,t.czdwdm

Because the data is encrypted, the selection of the status can only be ciphertext.

Here we need to have a certain understanding of the decode function. In fact, we can consider decode as a simple if-then-else statement. Syntax:

DECODE (value, if1, then1, if2, then2, if3, then3,... else)

Value indicates any column of any type in a table or any result obtained by calculation. When each value is tested, if the value is if1, the result of the Decode function is then1; if the value is if2, the result of the Decode function is then2; and so on. In fact, multiple if/then pairs can be provided. If the value result is not equal to any given pairing, the Decode result returns else.

 t.id,t.name,decode(t.sex,,,,, person t

For the preceding SQL statement, when sex = 1, the output is male, = 2, and the output is female. Otherwise, the output is demon.

So the sum of the preceding statistics: (decode (t. account_lx ,,,

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.