当前位置:网站首页>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')
边栏推荐
- How to associate wechat applet QR code to realize two code aggregation
- Sql语法中循环的使用
- 1212312321
- What management systems (Updates) for things like this
- Old love letters
- Pytorch中自己所定义(修改)的模型加载所需部分预训练模型参数并冻结
- tf.nn.top_k()
- String类学习
- Vs2022 offline installation package download and activation
- one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
猜你喜欢

卷妹带你学jdbc---2天冲刺Day2

家庭记账程序(第二版 加入了循环)

Consul服务注册与发现

Household accounting procedures (the second edition includes a cycle)

电商借助小程序技术发力寻找增长突破口

MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

Selective Search for Object Recognition 论文笔记【图片目标分割】

Gram matrix

Pytorch (environment, tensorboard, transforms, torchvision, dataloader)

Pytorch (network model training)
随机推荐
Win socket programming (Mengxin initial battle)
类和对象的学习
Cyclic displacement
Record how to modify the control across threads
SQL query time period content
Selective search for object recognition paper notes [image object segmentation]
Pytorch中自己所定义(修改)的模型加载所需部分预训练模型参数并冻结
Some doubts about ARP deception experiment
Redis底层数据结构
原型模式,咩咩乱叫
06. talk about the difference and coding between -is and = = again
Summary of the 10th provincial Blue Bridge Cup
家庭记账程序(第二版 加入了循环)
【C語言】深度剖析數據在內存中的存儲
The news of thunderbolt
Old love letters
Definition of Halcon hand eye calibration
转帖——不要迷失在技术的海洋中
pytorch(网络模型训练)
Soft power and hard power in program development