当前位置:网站首页>MySQL 02 function substr mod view view
MySQL 02 function substr mod view view
2022-07-19 07:28:00 【weixin_ fifty-three million two hundred and thirty-three thousa】
function
-- According to ID number Determine gender
SELECT MOD(SUBSTR(`idcard`,17,1),2) as 'gender' FROM `student`;
SELECT IF(MOD(SUBSTR(`idcard`,17,1),2),' Spirit boy ',' Grilled garlic girl ') as 'gender' FROM `student`;
-- According to ID number Find out all male information
SELECT * FROM `student` WHERE MOD(SUBSTR(`idcard`,17,1),2) = 1;
-- According to ID number Calculate the number of men and women
SELECT IF(MOD(SUBSTR(`idcard`,17,1),2),' Spirit boy ',' Grilled garlic girl ') as 'gender',COUNT(*) AS `count` FROM `student` GROUP BY `gender`;
-- According to ID number Calculate installation birthday sorting
SELECT UNIX_TIMESTAMP(SUBSTR(`idcard`,7,8)) as 'birthday' FROM `student` ORDER BY `birthday`;
SELECT DATE(SUBSTR(`idcard`,7,8)) as 'birthday' FROM `student` ORDER BY `birthday`;
-- According to ID number Calculate the age
SELECT DATE_FORMAT(SUBSTR(`idcard`,7,8),'%Y year %m month %d Japan ') as 'birthday' FROM `student` ORDER BY `birthday`;
SELECT YAER(DATE(SUBSTR(`idcard`,7,8))) as 'birthday' FROM `student` ORDER BY `birthday`;
SELECT MONTH(DATE(SUBSTR(`idcard`,7,8))) as 'birthday' FROM `student` ORDER BY `birthday`;
SELECT DAY(DATE(SUBSTR(`idcard`,7,8))),(DATE(SUBSTR(`idcard`,7,8))) as 'birthday' FROM `student` ORDER BY `birthday`;
-- If the current date month Greater than Date of birth
SELECT IF ((MONTH(NOW())- MONTH(DATE(SUBSTR(`idcard`,7,8)))) > 0,
YEAR(NOW())- YEAR(DATE(SUBSTR(`idcard`,7,8))),
IF ((MONTH(NOW())- MONTH(DATE(SUBSTR(`idcard`,7,8)))) < 0,
YEAR(NOW())- YEAR(DATE(SUBSTR(`idcard`,7,8))) - 1,
IF((DAY(NOW())- DAY(DATE(SUBSTR(`idcard`,7,8)))) > 0,
YEAR(NOW())- YEAR(DATE(SUBSTR(`idcard`,7,8))),
YEAR(NOW())- YEAR(DATE(SUBSTR(`idcard`,7,8))) - 1
)
)
) FROM student;
View
-- When querying a student, you can also query the student's professional grades
SELECT * FROM `student` WHERE `s_id` = 3;
SELECT `s`.`s_name`,``.`c_name`,`sc`.`score` FROM `student` s INNER JOIN `student_course` sc INNER JOIN `course` c
ON `s`.`s_id` = `sc`.`s_id` AND `sc`.`c_id` = `c`.`c_id` AND `s`.`s_id` = 3 ;
-- Create view
CREATE VIEW `stu_info` AS SELECT `s`.`s_id`,`s`.`s_name`,``.`c_name`,`sc`.`score` FROM `student` s INNER JOIN `student_course` sc INNER JOIN `course` c ON `s`.`s_id` = `sc`.`s_id` AND `sc`.`c_id` = `c`.`c_id`;
-- View query
SELECT * FROM `stu_info`
-- Modify view data
UPDATE `stu_info` SET `s_name` = ' Zhang Sanfeng ' WHERE `s_id` = 8;
-- Check and modify the view
SELECT * FROM `stu_info` WHERE `s_id` = 8;
-- Check the original data table after modifying the view
SELECT * FROM `student` WHERE `s_id` = 8;
-- Modify the original data table
UPDATE `stu_info` SET `s_name` = ' Zhang San ' WHERE `s_id` = 8;
-- Check the modified original data sheet
SELECT * FROM `student` WHERE `s_id` = 8;
-- Check the view after modifying the source data table
SELECT * FROM `stu_info` WHERE `s_id` = 8;
边栏推荐
- How to record enterprise or personal domain names
- M FPGA implementation of chaotic digital secure communication system based on Lorenz chaotic self synchronization, Verilog programming implementation, with MATLAB chaotic program
- Closures and decorators
- Data protection / disk array raid protection IP segment 103.103.188 xxx
- Speed feedback single closed loop DC speed regulation system based on Simulink
- 网络知识-03 数据链路层-PPP
- How to open the service of legendary mobile games? How much investment is needed? What do you need?
- FreeBSD 12 changing the background of the startup interface
- My world 1.12.2 Magic Baby (Fairy treasure dream) service opening tutorial
- 解决Mysql (1064) 错误: 1064 - You have an error in your SQL syntax;
猜你喜欢

Network knowledge-04 network layer IPv6

4.IDEA的安装与使用

m基于matlab的协作mimo分布式空时编码技术的仿真

Component emit Foundation

Web Security (XSS and CSRF)

How to output a digital diamond with a for loop

Network knowledge-05 transport layer TCP

Cracking Metric/Business Case/Product Sense Problems

网络知识-05 传输层-TCP

Steam game server configuration selection IP
随机推荐
The principle of SYN Flood attack and the solution of SYN Flood Attack
M simulation of 16QAM and 2DPSK communication links based on Simulink, and get the bit error rate curve by calling Simulink model through MATLAB
SQL skimming summary SQL leetcode review
m基于matlab的DQPSK调制解调技术的仿真
Slackware 14.2 installing KDE 5 plasma
Servlet notes
M BTS antenna design based on MATLAB, with GUI interface
m基于MATLAB-GUI的GPS数据经纬度高度解析与kalman分析软件设计
SNN learning diary - install spikengjelly
m基于matlab的超宽带MIMO雷达对目标的检测仿真,考虑时间反转
WCDMA soft handoff performance matlab simulation m, comparing the average number of activation sets (MasN), activation set update rate (Asur) and call interruption probability (OP) three performance i
4.IDEA的安装与使用
Closures and decorators
Review of 4121 Computer System for Data Science
网络知识-02 物理层
What if the website is hijacked?
Use of urllib Library
How does legend open its service? What do you need to prepare to open legend private server?
Review of 4705 NLP
MySQL解压版安装步骤(Windows)