Inquire
1. Simple query
SELECT * FROM info (table name)--Check all data
Select Code (column name), name (column name) from table name--Check the data for the specified column
Select Code (column name) as ' code ', name (column name) as ' name ' from info (change column name)--Assign alias to column
2. Conditional query
SELECT * FROM info (table name) where code (condition) = ' p001 '
SELECT * FROM info (table name) where sex (condition) = ' true ', and nation= ' n001 '--multi-conditional and relational
SELECT * FROM info (table name) where sex (condition) = ' true ', or nation= ' n001 '--multi-condition or relationship
3. Scope Query
SELECT * from table name where range
SELECT * from car where price>40 and price<50
SELECT * from car where price between and 50
4. Discrete query
SELECT * FROM car (table name) where code (column name) in (' c001 ', ' c005 ', ' c010 ', ' c015 ')
SELECT * from car where code not in (' c001 ', ' c005 ', ' c010 ', ' c015 ')
5. Fuzzy query
SELECT * FROM car (table name) where name (column name) like '% BMW (keyword)% '-check contains BMW's
SELECT * from car where name like ' BMW% '--look at the beginning of the BMW
SELECT * from car where name like '% BMW-check end of BMW '
SELECT * from car where name like ' BMW '--check etc with BMW's
SELECT * from car where name like '-e% '--check the third character is E's
% represents any number of characters
-Delegate is a character
6. Sort queries
Select *from Car (table name) Order BY price ASC--in ascending order of prices
Select *from Car (table name) Order BY price desc– in descending order
Select *from Car ORDER BY 0il DESC, price ASC-sorted in two fields, preceded by a secondary condition after the main condition
7. Paging Query
Select Top 5 * from car
Select Top 5 * from car where code not in (select Top 5 code from car)
Current page: page = 2 row= 10
Select top row *from car where code not in (select Top (page-1) * Row code from CAR)
8. Go to re-query
Select distinct brand from car
9. Group queries
Select brand from Car GROUP by Brand has count (*) >2
10. Aggregation function (statistical query)
How much data from car– query all data bars after select COUNT (*) query is complete
Select count (code) from car--query all data bars
Select SUM (Price (column name)) Sum from car (table name)
Select SUM (price) from car sum
Select SUM (price) from car sum
Select SUM (price) from car sum
Database SQL query