Oracle Analytics function--ration_to_report occupancy (percent)

Source: Internet
Author: User

Oracle has a lot of analytic functions, but this function will always forget, I think in this way can let myself remember, not next time Baidu.

Creation table, table data (usually practiced hand table):

Prompt PL/SQL Developer Importfileprompt Created onThursday, July 5, 2018 byAdministratorSetFeedbackoffSetDefineoffprompt Creating CKX001 ...Create TableCKX001 (IDVARCHAR2( -) not NULL, NAMEVARCHAR2( -) not NULL, SEXVARCHAR2( -) not NULL, SARLVARCHAR2( -), ADDRESSVARCHAR2( -), Time DATE) tablespace USERS pctfreeTenInitrans1Maxtrans255Storage (initial 64KNext8K minextents1Maxextents Unlimited);p rompt disabling triggers forCKX001 ...Alter TableCKX001 Disable Alltriggers;prompt Deleting CKX001 ...Delete  fromCKX001;Commit;p rompt Loading CKX001 ...Insert  intoCKX001 (ID, NAME, SEX, SARL, ADDRESS, time)Values('004','Chow Yun Fat','1',' -','Square',NULL);Insert  intoCKX001 (ID, NAME, SEX, SARL, ADDRESS, time)Values('005','Stephen Chow','1',' the','Shopping Malls',NULL);Insert  intoCKX001 (ID, NAME, SEX, SARL, ADDRESS, time)Values('006','Tony Leung','1','1700','Main Street',NULL);Insert  intoCKX001 (ID, NAME, SEX, SARL, ADDRESS, time)Values('001','Miriam Yeung','2',' -',NULL, To_date ('15-05-2018 10:54:19','dd-mm-yyyy Hh24:mi:ss'));Insert  intoCKX001 (ID, NAME, SEX, SARL, ADDRESS, time)Values('002','Cecilia Cheung','2',' +','Central Park', To_date ('15-05-2018 10:54:19','dd-mm-yyyy Hh24:mi:ss'));Insert  intoCKX001 (ID, NAME, SEX, SARL, ADDRESS, time)Values('003','Lizzy','2',' -','Hippo Apartments', To_date ('12-05-2018 10:54:44','dd-mm-yyyy Hh24:mi:ss'));Commit;p rompt6records loadedprompt enabling triggers forCKX001 ...Alter TableCKX001 Enable Alltriggers;SetFeedback onSetDefine onprompt done.

Now we are going to look at the percentage of each person's salary as the average wage:

Don't use ration_to_reropt when always use stupid method, because we ask everyone to the percentage of total wages first to the total wages, and then in that everyone's removal get,

Similar:

Select name,round(sarl/(selectsum from ckx001),4) *  - || ' % '  from ckx001;

Although the effect can be achieved, but we do not think that the actual development of the data is from a few tables, like the need to do a tear, data from the Personnel information table and the other 18 file table of this design,

In fact, the table design of the person has a hole in the brain, although the 18 Chapter table field is different, the majority of the class can be designed to a table, and then a file type of the fields to distinguish it, run off,

Anyway, what I'm going to say is that this percentage of SQL possible datum data comes in very difficult, and I don't want our example to come from a table, so it's easy, I was just looking at my own disgusting SQL

When you want to simplify him, at least to be beautiful and concise, and occasionally can put a force.

Like this:

Select name,roundover (),4)*|| ' % '  from ckx001;

The effect of the top two SQL is the same, but the party our basic data from the very complex SQL is, the following analysis function use will make your SQL clean and tidy.

Oracle Analytics function--ration_to_report occupancy (percent)

Related Article

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.