SQL application examples

Source: Internet
Author: User

1. Description: copy a table (only copy structure, source table name: A, new table name: B)
SQL: Select * into B from a where 1 <> 1;
2. Description: copy a table (copy data, source table name: A, target table name: B)
SQL: insert into B (a, B, c) Select D, E, F from B;
3. Description: displays the article, Submitter, and last reply time.
SQL: select a. Title, A. username, B. adddate
From table ,(
Select max (adddate) adddate
From table where table. Title = A. Title) B

4. Description: External join query (table name 1: A, table name 2: B)
SQL: select a. a, a. B, A. C, B. C, B. D, B. f
From a left out join B on A. A = B. C;

5. Note: Five minutes ahead of schedule reminder
SQL: Select *
From schedule
Where datediff (''minute '', F Start Time, getdate ()> 5

  
6. Note: two associated tables are used to delete information that is not in the secondary table.
SQL: delete from Info
Where not exists (
Select *
From infobz
Where info. INFID = infobz. INFID );

7. Note :--
SQL: select a. Num, A. Name, B. upd_date, B. prev_upd_date
From Table1, (select X. Num, X. upd_date, Y. upd_date prev_upd_date
From (select num, upd_date, inbound_qty, stock_onhand
From Table2
Where to_char (upd_date, ''yyyy/mm'') =
To_char (sysdate, ''yyyy/mm'') X,
(Select num, upd_date, stock_onhand
From Table2
Where to_char (upd_date, ''yyyy/mm'') =
To_char (to_date (to_char (sysdate, ''yyyy/mm '')
| ''/01'', ''yyyy/MM/dd'')-1, ''yyyy/mm'') y,
Where X. num = Y. Num (+) and X. inbound_qty
+ Nvl (Y. stock_onhand, 0) <> X. stock_onhand) B
Where a. num = B. Num;

  
8. Note :--
SQL: Select *
From studentinfo
Where not exists (select * from student where studentinfo. ID = student. ID)
And system name = ''" & strdepartmentname &"''
And Major name = ''" & strprofessionname &"''
Order by gender, place of origin, total score of the college entrance examination;

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.