当前位置:网站首页>SQL (basic 2)
SQL (basic 2)
2022-07-26 00:33:00 【Mourning】
DQL Basic query
● DQL(Data Query Language) Data query language query is one of the most frequently used operations , You can query data from a table , You can also query data from multiple tables .
● Basic query syntax : select Query list from Table name ;
● characteristic :
- The query list can be : Fields in the table 、 Constant 、 expression 、 function
- The result of the query is a virtual table
Query result processing :Specific column query :select column1,column2 from tableAll columns query : select * from tableArithmetic operator :+ - * /Exclude duplicate lines : select distinct column1,column2 from tableQuery function :select function ; / for example version()
Character functionslength(): Gets the number of bytes of the parameter valuechar_length() Get the number of characters of the parameter valueconcat(str1,str2,.....): String concatenationupper()/lower(): Capitalize a string / A lowercase lettersubstring(str,pos,length): Intercepting string Location slave 1 Startinstr(str, Specify the characters ): Returns the index of the first occurrence of the substring , If we can't find a way back 0trim(str): Remove spaces or substrings before and after the string ,trim( Specify substring from character string )lpad(str,length, Fill character ): The left padding with the specified character will str Fill to the specified lengthrpad(str,length, Fill character ): Right padding with the specified character will str Fill to the specified lengthreplace(str,old,new): Replace , Replace all substrings
INSERT INTO basketmember( name , Birthday , height , weight , Location )
VALUES(' Dwayne . wade ','1982-1-17',1.93,96,'null'),
(' lebron . James ','1984-12-30',2.03,113,' striker '),
(' Kobe . Bryant ','1978-8-23',1.92,99,' defender '),
(' Deco . Dirk Nowitzki ','1978-6-19',2.13,111,'null'),
(' Iris . Paul ','1985-5-6',1.82,79,' defender '),
(' Tony . Parke ','1982-5-17',1.87,83,' defender '),
(' Kevin . Garnett ','1981-7-14',2.12,113,'null'),
(' Paul . Pierce ','1977-10-13',2.00,106,' striker '),
(' Michael . Jordan ','1963-2-17',1.98,98,' striker '),
(' Dwight - Howard ','1985-12-18',2.10,120,' Center-forward '),
(' Yao Ming ','1980-9-12',2.29,140,' Center-forward '),
(' Shaquille . O'Neill ','1972-3-6',2.15,147,' Center-forward ') 
This example is the case we used today !!!
SELECT Number , name , Location FROM basketmember WHERE Number =2 # Select a fixed column in the table 
SELECT*FROM basketmember ORDER BY( weight )# Sort the selected columns 
SELECT*FROM basketmember LIMIT 0,2# Select the selected column ( initial , end ) That's ok 
SELECT DISTINCT name , Birthday FROM basketmember# Remove duplicate data , Duplicate data means that each column has the same value 
SELECT Number , height + weight FROM basketmember# Add some columns 
SELECT LENGTH( name )FROM basketmember# Output in bytes 
SELECT CHAR_LENGTH( name )FROM basketmember# Output in string 
SELECT UPPER( name )FROM basketmember# Turn capitalization ![]()
SELECT LOWER( name )FROM basketmember# Turn lowercase ![]()
SELECT INSTR( name ,'i')FROM basketmember# Returns the position where the specified character first appears in the character 
SELECT SUBSTRING( name ,1,2)FROM basketmember# Intercept the string content from the beginning to the end 
SELECT TRIM( name )FROM basketmember# Remove the space before and after 
SELECT TRIM('i'FROM name )FROM basketmember# Remove the string before and after the column name ![]()
SELECT LPAD( name ,8,'a')FROM basketmember# Add characters to the front until they meet the given character length 
SELECT RPAD( name ,8,'b')FROM basketmember# Add characters to the end of a given character length 
SELECT REPLACE( name ,' Yao Ming ',' Liu Ziwen ')FROM basketmember# Replace ( used , new )
Logical processing :
case when Conditions then result 1 else result 2 end; There can be multiple when
ifnull( Detected value , The default value is ) The function detects whether it is null, If null, Then return the specified value , Otherwise return to
The value of the original
if function : if else Of effect if( Conditions , result 1, result 2)
SELECT name , Birthday ,
(CASE WHEN height >=2.00 THEN' Giant '
WHEN height <=1.99 AND height >=1.8 THEN' secondary ' ELSE' Not medium ' END
)AS height
FROM basketmember#when sentence 
SELECT Number , name ,IFNULL( height ,' Not entered yet ')FROM basketmember# To determine if there is null, Fill in default SELECT Number , name ,IF( height >=2.00,' tall ',' Low man ')AS height FROM basketmember#if Judgment statement 
- round( The number ): rounding
- ceil( The number ): Rounding up , return >= The smallest integer of this parameter
- floor( The number ): Rounding down , return <= The maximum integer of the parameter
- truncate( The number , Keep the number of decimal places ): truncation , Truncate to several digits after the decimal point
- mod( Divisor , Divisor ): Remainder , The divisor is positive , It's positive ; The divisor is negative , It's negative
- rand(): Get random numbers , return 0-1 Decimal between
- now(): Returns the current system date + Time
- curdate(): Returns the current system date , Not including time
- curtime(): Return current time , No date included You can get the specified part , year 、 month 、 Japan 、 Hours 、 minute 、 second
- YEAR( Date column ),MONTH( date Column ),DAY( date Column ) , HOUR( date Column ) ,MINUTE( date Column )SECOND( date Column )
- str_to_date: Convert the character of date format to the date of specified format
- date_format: Convert date to string
- datediff(big,small): Returns the number of days between two dates

function : For statistical use , Also known as aggregate function or statistical function or group function
classification :sum Sum up 、avg Average 、max Maximum 、min minimum value 、count Count ( Non empty )
1.sum,avg Generally used to deal with numerical type max,min,count Can handle any type of
2. All the above grouping functions are ignored null value
3.count General use of functions count(*) Used to count lines
4. The field requirement to query with grouping function is group by Fields after
SELECT SUM( weight )FROM basketmember# The sum of the 
SELECT AVG( weight )FROM basketmember# Average 
SELECT MAX( weight )FROM basketmember# Maximum 
SELECT MIN( weight )FROM basketmember# minimum value 
Use WHERE Clause , Filter out rows that do not meet the criteria ,WHERE Clause in the wake of FROM Clause .
grammar :select < result > from < Table name > where < Conditions >
Compare =, != or <>, >, <, >=, <=
Logical operations
- and And
- or or
- not Not
SELECT *FROM basketmember WHERE height BETWEEN 1.80 AND 2.00# In a Within the interval , Include boundary values 
Fuzzy query
LIKE : Whether it matches a pattern Generally used with wildcards , You can judge character type or numeric type .
wildcard : % Any number of characters , contain 0 Characters _ Any single character
between and Between the two , Contains a critical value ;
in Determine whether the value of a field belongs to in An item in the list
IS NULL( Empty ) or IS NOT NULL( Not empty )
SELECT *FROM basketmember WHERE name LIKE(' a surname %')# Keyword matches any character 
边栏推荐
- MPLS实验
- TID-MOP:面向数据交易所场景下的安全管控综合框架
- 白蛋白纳米粒表面修饰低分子量鱼精蛋白LMWP/PEG-1900修饰牛血清白蛋白制备研究
- Research on the integrated data quality management system and technical framework under the scenario of data circulation and transaction
- mysql事务的四大特性以及隔离级别
- 使用LocalDate类完成日历设计
- Revision of Journal of Computational Physics
- 向左旋转k个字符串(细节)
- Eight common SQL misuses of MySQL, all of which I have learned
- markdown写作平台
猜你喜欢

Study on bovine serum protein modified phenolic acids and alkaloids small molecules / coupled microspheres protein / bovine erythrocyte SOD

Redis(八) - Redis企业实战之优惠券秒杀

Redis killed twelve questions. How many questions can you carry?

SQL server failed to send mail, prompting that the recipient must be specified

本地电脑架设传奇怎么开外网叫朋友一起玩?

MySQL - Multi version concurrency control (mvcc)

二进制表示--2的幂

基于MFFMB的电商评论文本分类研究

Sorting out the encapsulation classes of control elements in appium

sql(基础二)
随机推荐
数据流通交易场景下数据质量综合管理体系与技术框架研究
C语言 预处理详解
Redis夺命十二问,你能扛到第几问?
Research on text classification of e-commerce comments based on mffmb
SQL server failed to send mail, prompting that the recipient must be specified
In order to grasp the redis data structure, I drew 40 pictures (full version)
8种MySQL常见SQL错误用法,我全中
软件测试同行评审到底是什么?
如何用120行代码,实现一个交互完整的拖拽上传组件?
【Redis】② Redis通用命令;Redis 为什么这么快?;Redis 的数据类型
12.神经网络模型
DC-6--vulnhub靶场
实战演练 | 查找在给定时间范围内购买超过 N 件商品的客户
mysql事务的引入
Understanding of "dbdnet: a deep boosting strategy for imagedenoising"
The way of understanding JS: what is prototype chain
Jd.com API for obtaining recommended product list
CountDownLatch
你还在掐表算时间复杂度?
Distributed transactions: the final consistency scheme of reliable messages