当前位置:网站首页>SQL basic query
SQL basic query
2022-06-11 08:52:00 【Lizexin】
Basic query method :
select Field from Table name ;
select * from Table name ;
duplicate removal
select distinct Field from Table name ;
Basic condition query
select Field from Table name where Conditions Operator value ;
| Operator | name |
|---|---|
| = | be equal to |
| <> | It's not equal to |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| <= | Less than or equal to |
| BETWEEN | In a certain range |
| LIKE | contain |
notes :
In some versions of sql in , The operator <> Can be written as !=.
sql Use single quotation marks in to surround the text value ( Most database systems also accept double quotes ), Values don't use quotation marks .
and and or Operator
and: If the first condition and the second condition hold , be and Operator to display a record .
or: If only one of the first condition and the second condition holds , be or Operator to display a record .
select Field from Table name where Field Operator value and/or Conditions Operator value ;
notes :and And or combination ( Use parentheses to form complex expressions )
select Field from Table name where ( Conditions Operator value and/or Conditions Operator value ) and/or Conditions Operator value ;
order by Default sort
desc In reverse order
select Field from Table name order by or desc;
Insert
insert into Table name values ( value 1, value 2,...);
insert into Table name ( Field 1, Field 2) voalues ( value 1, value 2,...);
modify
update Table name set Field = The new value where Field = Certain value ;
Delete
drop Delete table : Delete content and definition , Release space
drop table Table name ;
delete Delete content , Do not delete table structure , Delete line by line
delete table Table name ;
delete from Table name where Conditions = value ;
truncate Delete content 、 Release space , But don't delete the table structure ;
truncate table Table name ;
like Fuzzy query
select Field from Table name where Field like 'N%';
notes :“%” Can be used for the first wildcard
wildcard describe
% Replace one or more characters
_ Replace only one character
[charlist] Any single character in the character column
[^charlist] perhaps [!charlist] Any single character not in the character column
in
select Field from Table name where Field in (value1,value2,...);
between…and Select a data range between two values , These values can be numerical 、 Text or date .
select Field from Table name where Field between value1 and value2;
Alias Alias
The table alias :
select Field from Table name as name ;
The alias of the field :
select Field as name from Table name ;
join
join The field contents and values are consistent inner join Internal connection : The result is the intersection of the two sides
select Field from Table name 1 inner jion Table name 2 on Table name 1. Field = Table name 2. Field
left join Left connection : Based on the table on the left , Whether the conditions are met or not, all the data on the left will be displayed , The data on the right shows only those that can be matched , Use when it doesn't match null fill ;
select Field from Table name 1 left jion Table name 2 on Table name 1. Field = Table name 2. Field
right join The right connection : The way of understanding is the same as the left connection , It's just that the table on the right is used as the benchmark , To match the data on the left , Only those that can be matched are displayed , No match null fill ;
select Field from Table name 1 right jion Table name 2 on Table name 1. Field = Table name 2. Field
FULL OUTER JOIN: Full connection , The result is a table A And table B Union , That is to say, it will all be displayed
SELECT Field
FROM surface 1
FULL OUTER JOIN surface
ON surface 1. Field = surface 2. Field ;
Cross join: Cross connect
SELECT Field FROM surface 1 CROSS JOIN surface 2 WHERE Conditions ;
or
SELECT Field FROM surface 1, surface 2 WHERE Conditions ;
union Inside select Statements must have the same number of columns .
Columns must be of the same type , At the same time, the column name order must be the same .
Different types can be cast cast ( Field as type :int float double varchar char etc. )
select Field from Table name 1
union
select Field from Table name 2
notes : Default union Operator selects different values , If duplicate values are allowed , You can use union all.
select into Add temporary table
select into Statement selects data from a table , Then insert the data into another temporary table .
select * into A temporary table from old surface ;
select * into A temporary table from old surface where Conditions Operator value ;
select count()
count(*) Function returns the number of record rows in the table :
select count(*) from Table name ;
select sum ()
sum Function returns the total number of columns of numbers ( Total ).
select sum( Field ) from Table name ;
notes : Usually cooperate group by Use ;
group by
group by Used to combine the total function , Group result sets according to one or more columns ;
select Field 1,sum( Field 2) from Table name group by Field 1;
边栏推荐
- [cvpr2022] intensive reading of querydet papers
- BS 7176 fire resistance test for upholstered furniture
- Codeworks round 723 (Div. 2)
- leetcode - 518. Change II
- The leader asked me to rewrite the test code. Should I do the same?
- Supplementary provision plan codeworks round 760 (Div. 3)
- Interprocess communication
- Heap can also be regarded as a tree structure. It is specified that the root node must be greater than or less than the left and right child nodes, but the size order of the left and right child nodes
- M1 芯片指南:M1、M1 Pro、M1 Max 和 M1 Ultra
- E. X的放大与缩小(运算符重载)
猜你喜欢
随机推荐
MySQL核心点笔记
Codeworks round 680 div2
leetcode - 460. LFU cache
Redis6 entry-level tutorial. There are integration cases. You can directly see the integration cases. It is easy to get started
Matlab学习8-图像处理之线性与非线性锐化滤波、非线性平滑滤波
利用docker-compose搭建redis5集群
Usage and difference between map and set in JS
Introduction to knowledge atlas -- yedda annotation
PVC 塑料片BS 476-6 火焰传播性能测定
马志强:语音识别技术研究进展和应用落地分享丨RTC Dev Meetup
Introduction to database system experiment report answer Experiment 5: database single table query
Display DIN 4102-1 Class B1 fire test requirements
【C语言-数据存储】数据在内存中是怎样存储的?
Zookepper===> animal management system
Heap can also be regarded as a tree structure. It is specified that the root node must be greater than or less than the left and right child nodes, but the size order of the left and right child nodes
What if the copied code format is confused?
领导让我重写测试代码,我也要照办嘛?
redis6 入门级教程,有整合案例,可以直接看整合案例,简单入门,直接上手
EN 45545-2T10水平法烟密度检测的注意事项
一些学习记录i=









