Usage of in and other aspects of SQL statements

Source: Internet
Author: User

SELECT * FROM Txt1

SELECT * FROM Txt2
SELECT * from TXT1 where name in (select name from txt2 where chk = 0)
SELECT * from TXT1 where name is not in (select name from txt2 where chk = 0)
SELECT * FROM Txt1 inner join txt2 on txt1.name = Txt2.name
SELECT * from txt1 LEFT join txt2 on txt1.name = Txt2.name
SELECT * from Txt1 right join txt2 on txt1.name = Txt2.name
SELECT * from txt1,txt2 where txt1.name = Txt2.name Order by txt2.id Desc
Select Txt1.name,sum (txt1.sumint) from txt1,txt2 where Txt1.name =txt2.name Group by Txt1.name
Select count (txt1.name), sum (sumint) from Txt1,txt2 where Txt1.name =txt2.name have sum (sumint) <10
Select count (txt1.name), sum (sumint) from Txt1,txt2 where Txt1.name =txt2.name have sum (sumint) >50
SELECT * from Txt1,txt2 where Txt1.name <>txt2.name Order by Txt1.name Compute Sum (sumint) by Txt1.name
Insert INTO TXT3 select Name,sumint from Txt1
In: Equivalent connection, used to find records of the same field in multiple tables
Not in: Non-equivalent connection, used to find records that do not exist
Inner join: Internal connection, used primarily to find records that are eligible
Left join: To find the right side, mainly for the left.
Right join: Use to find the left side, mainly to the right, with NULL to express
ORDER BY: Ascending ASC Descending desc
GROUP BY: Grouping Sort by field (for example, by Class), using an aggregate function exists
Having: to judge a grouping condition, use it to make sure that each field is using the aggregate function
COMPUTE by: Clauses enable you to view both detail rows and summary rows with the same SELECT statement. You can calculate a summary value for a subgroup, or you can calculate a summary value for the entire result set.
The name of the row aggregate function; For example, SUM, AVG, MIN, MAX, or COUNT
INSERT INTO: Inserts the query's statement into the new table primarily.
Data for TXT1 tables
ID Name Sumint
1 Sheets 355
2 Li 485
3 Wang 585
4 Zhao 6,855
Data for TXT2 tables
ID Name CHK
1 Sheets 30
2 Lee 41 1
3 Wang 50
4 Zhao 60

Usage of in and other aspects of SQL statements

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.