Oracle SQL Test 1

Source: Internet
Author: User

Oracle SQL Test 1 SQL code www.2cto.com id sname smoney sprovince 1 zhangsan 2098 A 2 lisi 3000 B 3 wangwu 6789 C 4 liumazi 4587 C 5 dongjiu 3298 B 6 shiga 4567 A id: contract id sname: Name smoney: Performance sprovince: Region create table test (sid NUMBER, sname VARCHAR2 (20), smoney NUMBER, sprovince CHAR (1) insert into test VALUES (1, 'hangsan', 2098, 'A'); insert into test VALUES (2, 'lisi', 3000, 'B'); INSERT INTO test VALUES (3, 'hangw ', 6789, 'C'); insert into test VALUES (4, 'liumazi', 4587, 'C'); insert into test VALUES (5, 'dongjiu', 3298, 'B'); INSERT INTO test VALUES (6, 'shiga ', 4567, 'A'); COMMIT; -- show the name of the Contract id whose performance is greater than the average value of the same region. SELECT t. * FROM test t, (select avg (smoney) smoney, sprovince FROM test group by sprovince) t2 WHERE t. smoney> t2.smoney AND t. sprovince = t2.sprovince or SELECT t. * FROM test t WHERE t. smoney> (select avg (smoney) FROM test t2 WHERE t. sprovince = t2.sprovince group by t2.sprovince) -- inserts the average performance region of the same region into the new TABLE (the new TABLE only contains two fields: average performance region) create table test_temp as select avg (t. smoney) smoney, t. sprovince FROM test t group by t. sprovince

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.