"SQL" Oracle generates temporary tables

Source: Internet
Author: User

In everyday SQL queries, we need to process the data that we want to query, and then query it in the pre-processed data. At this point we need to use the temporary table, pre-processing the data into the temporary table, and then in the temporary list according to the conditions we need to query.

Let's say we have an income table: Incoming, the fields are: id,name,amt,cur we require that each person's AMT be converted into $ after and. Due to the difference in currency, we need to convert the Amt currency into renminbi in advance and then calculate the currency.

Another table is the XRT table, which holds the RMB premium for each currency.

There are two methods, one is to use the with as method, to generate a temporary table temp, and then in this temporary list.

With temp as (select Name, amt* (select Cnyrate from XRT x where x.cur=i.cur) from incoming) select name, SUM (AMT) from Inc Oming GROUP BY name

The second method is to use the Select method

Select Name,sum (AMT) from (select name,amt* (selct cnyrate from XRT x where x.cur=i.cur) from incoming) the temp group by name;

  

"SQL" Oracle generates temporary tables

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.