当前位置:网站首页>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 
边栏推荐
- How to make your JS code more beautiful
- Trial division -- power of 3
- [redis] ② redis general command; Why is redis so fast?; Redis data type
- 对比7种分布式事务方案,还是偏爱阿里开源的Seata(原理+实战)
- DC-6--vulnhub靶场
- Multitask programming
- Nest.js 用了 Express 但也没完全用
- MPLS实验
- MPLS experiment
- Four characteristics and isolation level of MySQL transactions
猜你喜欢

对“DOF: A Demand-oriented Framework for ImageDenoising“的理解

Tid-mop: a comprehensive framework for security management and control under the scenario of data exchange

融合聚类信息的技术主题图可视化方法研究

数据库工具对决:HeidiSQL 与 Navicat

MPLS experiment

基于数据要素流通视角的数据溯源研究进展

Redis夺命十二问,你能扛到第几问?

PC website realizes wechat code scanning login function (II)

Binary representation -- power of 2

测试7年,面试华为最后面议要薪1万,HR说我不尊重华为,他们没有那么低薪资的岗位~
随机推荐
对比7种分布式事务方案,还是偏爱阿里开源的Seata(原理+实战)
你还在掐表算时间复杂度?
Preparation of bovine erythrocyte superoxide dismutase sod/ folic acid coupled 2-ME albumin nanoparticles modified by bovine serum albumin
2022/7/24 考试总结
本地电脑架设传奇怎么开外网叫朋友一起玩?
白蛋白纳米-超声微泡载组织型纤溶酶原激活物基因靶向制备研究
What are the precautions for using MySQL index? (answer from six aspects)
Representation and implementation of stack (C language)
JVM 三色标记法与读写屏障
Eight common SQL misuses of MySQL, all of which I have learned
mysql事务的引入
为了拿捏 Redis 数据结构,我画了 40 张图(完整版)
In order to grasp the redis data structure, I drew 40 pictures (full version)
数据库工具对决:HeidiSQL 与 Navicat
Use of redis
HOOPS Exchange助力混合计算流体动力学软件搭建3D格式导入读取功能 | 客户案例
MPLS实验
Research progress of data traceability based on the perspective of data element circulation
2022/7/19 考试总结
Thymeleaf view integration