- 查询操作
# set的用法;like的用法,注意‘’
# 方法1
set @var1=1, @var4=(select report_uuid from report_reportinfo where report_path like '%20210112%' limit 1);
select @var1, @var4;
delete from report_reportdetail where fk_report_uuid_id =@var4;
delete from report_report_reportperiod where fk_report_uuid_id =@var4;
delete from report_reportinfo where report_uuid =@var4;
# 方法2 (推荐)
set @var0=20210112;
set @var1=(select report_uuid from report_reportinfo where report_path like concat( '%' ,@var0, '%' ) limit 1);
select @var1;
delete from report_reportdetail where fk_report_uuid_id =@var1;
delete from report_report_reportperiod where fk_report_uuid_id =@var1;
delete from report_reportinfo where report_uuid =@var1;
# 将SQL查询结果作为查询条件进行查询
# 1. 单行子查询 :单行比较符号(=, >, <, >=, <=, <>)
select ename,deptno,sal from emp where deptno=(select deptno from dept where loc='XI AN');
# 2. 多行子查询: 必须用多行比较符号(IN,ALL,ANY)来进行比较,ALL 和ANY 操作符都不可以单独使用,只能与单行比较符(=、>、< 、>= 、<= 、<>)结合使用
# 查询选修了老师名叫Lee(假设唯一)的学生名字:
select stName from Student where stId in(select distinct stId from score where teId=(select teId from teacher where teName='Lee'));
# 查询所有部门编号为A的资料:
SELECT ename,job,sal FROM EMP WHERE deptno in ( SELECT deptno FROM dept WHERE dname LIKE 'A%');
# 多行子查询使用ALL操作符:查询有一门以上的成绩高于Lee的最高成绩的学生的名字:
select stName from Student where stId in(select distinct stId from score where score >all(select score from score where stId=(select stId from Student where stName= 'Lee') ));
# 多行子查询使用ANY操作符号例子:查询有一门以上的成绩高于Lee的任何一门成绩的学生的名字:
select stName from Student where stId in(select distinct stId from score where score >any(select score from score where stId=(select stId from Student where stName='Lee')));
# 时间相关的查询
# 查询7天内的数据
SELECT * FROM db5.report_reportdetail where (case_name = 'Throughput' or case_name = 'Traffic') and result = 'pass' and date_sub(CURDATE(),INTERVAL 7 DAY) <= DATE(report_create_time) order by report_create_time desc ;
# 参考
https://blog.csdn.net/ls1645/article/details/79118464
# group by 处理字符串聚合的方法
SELECT AVG(time2.`Rx Carrier deactivate time in radio`) as soap1, AVG(time1.rru_reset_detected) as warm_reset_detected,AVG(time1.rru_reset_enable) as warm_reset_enable,AVG(time1.rru_reset_onair) as warm_reset_onair,AVG(time1.rru_reset_detected)+AVG(time1.rru_reset_enable)+AVG(time1.rru_reset_onair) as totol,version1.rru_vesion FROM report_report_reportperiod AS time1 LEFT JOIN report_parse_soap_result AS time2 on time1.fk_report_uuid_id = time2.fk_report_uuid_id LEFT JOIN report_reportinfo AS info1 on time1.fk_report_uuid_id = info1.report_uuid LEFT JOIN report_reportdetail AS version1 on time1.fk_report_uuid_id = version1.fk_report_uuid_id where time1.rru_reset_detected >0 and info1.platform_name='AEQE' group by version1.rru_vesion;
# group by 处理字符串聚合的方法+替换
SELECT AVG(time2.`PTP sync time BETWEEN RU AND DU`) AS PTP_sync
,AVG(time2.`Radio data path sync time`) AS path_sync
,AVG(time2.`Tx Carrier setup time IN radio`) AS Tx_setup
,AVG(time2.`Rx Carrier setup time IN radio`) AS Rx_setup
,AVG(time2.`Tx Carrier activate time IN radio`) AS Tx_activate
,AVG(time2.`Rx Carrier activate time IN radio`) AS Rx_activate
,AVG(time2.`Tx Carrier deactivate time IN radio`) AS Tx_deact
,AVG(time2.`Rx Carrier deactivate time IN radio`) AS Rx_deact
,AVG(time1.rru_reset_detected) AS reset_detected
,AVG(time1.rru_reset_enable) AS reset_enable
,AVG(time1.rru_reset_onair) AS reset_onair
,AVG(time1.rru_reset_detected)+AVG(time1.rru_reset_enable)+AVG(time1.rru_reset_onair) AS totol_reset_time
,left(replace(version1.rru_vesion,'RFSW Vesion:',''),31) AS RRU_version
,left(GROUP_CONCAT(version1.bbu_vesion),30) AS BBU_version
FROM report_report_reportperiod AS time1
LEFT JOIN report_parse_soap_result AS time2
ON time1.fk_report_uuid_id = time2.fk_report_uuid_id
LEFT JOIN report_reportinfo AS info1
ON time1.fk_report_uuid_id = info1.report_uuid
LEFT JOIN report_reportdetail AS version1
ON time1.fk_report_uuid_id = version1.fk_report_uuid_id
WHERE time1.rru_reset_detected >0
AND info1.platform_name='AEQE'
GROUP BY version1.rru_vesion;
- 修改操作
# order by id desc limit 20 都是用来修饰where的,也就是说只是修改 20个最大的ID
update report_reportdetail set case_name = 'Throughput' where case_name = 'Traffic' and result = 'pass' order by id desc limit 20 ;
- 创建数据库
CREATE DATABASE IF NOT EXISTS `DatabaseName1` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE `DatabaseName2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
create database DatabaseName3 DEFAULT CHARACTER set utf8;
show databases;
drop database <数据库名>;
- 创建表
use db1
CREATE TABLE person2(id INTEGER PRIMARY KEY NOT NULL,time TEXT NOT NULL,name varchar(100) NOT NULL);
insert into person2(time, name) values('1', 'bill')
insert into person2(id,time, name) values(1,'1', 'bill'); # id 不是自动
# 应用
CREATE TABLE `db5`.`report_l1_statistics_time` (
`id_report_l1_statistics_time` INT NOT NULL,
PRIMARY KEY (`id_report_l1_statistics_time`));
- navicat对应操作
https://jingyan.baidu.com/article/9989c746d0ae18f648ecfefc.html
4.mysql 远端连接方法
https://cloud.tencent.com/developer/article/1153843
1、显示密码
如:MySQL 连接远程数据库(192.168.5.116),端口“3306”,用户名为“root”,密码“123456”
C:/>mysql -h 192.168.5.116 -P 3306 -u root -p 123456
2、隐藏密码
如:MySQL 连接本地数据库,用户名为“root”,
C:/>mysql -h localhost -u root -p
Enter password: