当前位置:网站首页>MySQL-05
MySQL-05
2022-06-26 05:58:00 【Mr.Rop】
5、MySQL function
5.1 Common functions
-- ================ Common functions ===============
-- Mathematical operations
SELECT ABS(-8) -- The absolute value
SELECT CEILING(9.4) -- Rounding up
SELECT FLOOR(9.4) -- Want to round down
SELECT RAND() -- Return to one 0-1 Random number between
SELECT SIGN(10) -- Judge the sign of a number 0-0, A negative number returns -1, A positive number returns 1
-- String function
SELECT CHAR_LENGTH(' Even the smallest sail can sail far ') -- String length
SELECT CONCAT(' I ',' It's called ',' What ',' Well ') -- String splicing
SELECT INSERT(' I love programming. helloworld',1,2,' Super love ') -- Inquire about , Replace ( Replace a certain length from a certain position )
SELECT UPPER('KuangShen') -- Convert all to uppercase
SELECT LOWER('KuangShen') -- Convert all to lowercase
SELECT INSTR('kuangshen','h') -- Returns the index of the first occurrence of the substring
SELECT REPLACE(' Crazy God says persistence can succeed ',' insist ',' Strive ') -- Replace the occurrence of the specified string
SELECT SUBSTR(' Crazy God says persistence can succeed ',4,6) -- Returns the specified string ( Original string , Intercept location , Interception length )
SELECT REVERSE(' It was a pig ') -- reverse
-- Inquire about the classmate surnamed Zhang , name -> Zou
SELECT REPLACE(StudentName,' Zhang ',' Zou ') FROM student
WHERE StudentName LIKE ' Zhang %'
-- Event and date functions ( remember )
SELECT CURRENT_DATE() -- Get current date
SELECT CURDATE() -- Get current date
SELECT NOW() -- Get current date , Time
SELECT LOCALTIME() -- Local time
SELECT SYSDATE() -- system time
SELECT YEAR(NOW())
SELECT MONTH(NOW())
SELECT DAY(NOW())
SELECT HOUR(NOW())
SELECT MINUTE(NOW())
SELECT SECOND(NOW())
-- System
SELECT SYSTEM_USER()
SELECT USER()
SELECT VERSION()
5.2 Aggregate functions ( Commonly used )
The name of the function | describe |
---|---|
COUNT() | Count |
SUM() | Sum up |
AVG() | Average |
MAX() | Maximum |
MIN() | minimum value |
… |
-- ========== Aggregate functions ==============
-- Can count Table data ( Want to query how many records there are in a table , Just use count())
SELECT COUNT(StudentName) FROM student; -- count( Field ), Will ignore all null value
SELECT COUNT(*) FROM student -- count(*), Will not ignore null value , The essence Count lines
SELECT COUNT(1) FROM student -- count(1), Will not ignore all null value The essence Count lines
SELECT SUM(`StudentResult`) AS The sum of the FROM result;
SELECT AVG(`StudentResult`) AS average FROM result;
SELECT MAX(`StudentResult`) AS The highest FROM result;
SELECT MIN(`StudentResult`) AS Lowest score FROM result;
5.3、 database-level MD5 encryption ( Expand )
What is? MD5?
It mainly enhances the complexity and irreversibility of the algorithm
MD5 Irreversible , Specific values MD5 It's the same
MD5 How to crack websites , There is a dictionary behind them ,MD5 Encrypted value , Encrypted pre value
-- ============= test MD5 encryption =============
CREATE TABLE `testmd5`(
`id` INT(4) NOT NULL,
`name` VARCHAR(20) NOT NULL,
`pwd` VARCHAR(50) NOT NULL,
PRIMARY KEY(`id`)
)ENGINE=INNODB DEFAULT CHARSET=utf8
-- Plaintext password
INSERT INTO testmd5 VALUES(1,'zhangsan','123456'),(2,'lisi','123456'),(3,'wangwu','123456')
-- encryption
UPDATE testmd5 SET pwd=MD5(pwd) WHERE id=1
UPDATE testmd5 SET pwd=MD5(pwd) -- Encrypt all passwords
-- Encrypt when inserting
INSERT INTO testmd5 VALUES(4,'xiaoming',MD5('123456'))
-- How to check : The password passed in by the user , Conduct md5 encryption , Then compare the encrypted values
SELECT * FROM testmd5 WHERE `name`='xiaoming' AND pwd=MD5('123456')
边栏推荐
猜你喜欢
解决在win10下cmder无法使用find命令
Bubble sort
Ribbon负载均衡服务调用
Adapter mode
电商借助小程序技术发力寻找增长突破口
Pytorch (environment, tensorboard, transforms, torchvision, dataloader)
工厂方法模式、抽象工厂模式
Getting started with Python
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast
Pytorch (network model training)
随机推荐
DOM文档
Redis多线程与ACL
The purpose of writing programs is to solve problems
Ribbon负载均衡服务调用
numpy.log
Vs2022 offline installation package download and activation
小程序第三方微信授权登录的实现
Status mode, body can change at will
E-commerce seeks growth breakthrough with the help of small program technology
家庭记账程序(第一版)
[C language] deep analysis of data storage in memory
numpy.random.choice
RIA想法
Bubble sort
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast
C XX management system
Household accounting procedures (the second edition includes a cycle)
numpy. exp()
卷妹带你学jdbc---2天冲刺Day2