当前位置:网站首页>mysql的基础命令
mysql的基础命令
2022-07-06 06:26:00 【luckyyuanyuan】
sql区别大小写问题
创建数据表:
CREATE TABLE IF NOT EXISTS `runoob_tbl`(
`runoob_id` INT UNSIGNED AUTO_INCREMENT,
`runoob_title` VARCHAR(100) NOT NULL,
`runoob_author` VARCHAR(40) NOT NULL,
`submission_date` DATE,
PRIMARY KEY ( `runoob_id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
1. 设置字段的属性为 NOT NULL, 在操作数据库时如果输入该字段的数据为NULL ,就会报错。
2. AUTO_INCREMENT定义列为自增的属性,一般用于主键,数值会自动加1。
3. PRIMARY KEY关键字用于定义列为主键。 您可以使用多列来定义主键,列间以逗号分隔。
4. ENGINE 设置存储引擎,CHARSET 设置编码。
根据表中某一列的“PH”字段查找数据,并限制只显示查找的前1000行
select * from dm_oss.d_f_oss_device_service_info where device_id like '%PH%' limit 1000
查询数据某一列中有哪些值(去重)
select distinct device_id from dm_oss.d_f_oss_device_service_info where device_id
指定被插入列名和值进行插入:
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
在 “device_id ” 字段中查询属性值中含有 “PH” 的数据,并限制只展现1000行
select * from device_service_info where device_id like '%PH%' limit 1000

select * from device_basic_info where device_id like '%PH%' limit 1000

案例一: 多表联合查询与统计
表1:device_service_info
表2:device_basic_info
步骤1:查询1.4.9类的版本
// 在 “software_version ” 字段中查询属性值中含有 “1.4.9” 的数据
select device_id, description, software_version from device_basic_info having software_version like '%1.4.9%'

步骤2:根据service_start_time 字段选择某一段时间的数据
select device_id, service_id from device_service_info having service_start_time between "${day_start}" and "${day_end}"

步骤3:计算每个设备在指定的某段时间内的服务次数
select device_id, count(service_id) as service_sum from (select device_id, service_id from device_service_info having service_start_time between "${day_start}" and "${day_end}") group by device_id

步骤4:拼接两张表的信息,采取内连接,取其交集;
select t1.device_id, t1.service_sum, t2.description, software_version from ((select device_id, count(service_id) as service_sum from (select device_id, service_id from dm_oss .d_f_oss_device_service_info having service_start_time between "${day_start}" and "${day_end}") group by device_id) t1) inner join ((select device_id, description, software_version from dm_oss.d_f_oss_device_basic_info having software_version like '%1.4.9%') t2 )on t1.device_id = t2.device_id

边栏推荐
- 模拟卷Leetcode【普通】1143. 最长公共子序列
- 删除外部表源数据
- Testing of web interface elements
- Simulation volume leetcode [general] 1314 Matrix area and
- Set the print page style by modifying style
- LeetCode 729. My schedule I
- 中英对照:You can do this. Best of luck祝你好运
- 英语论文翻译成中文字数变化
- [mqtt from getting started to improving series | 01] quickly build an mqtt test environment from 0 to 1
- Manage configuration using Nacos
猜你喜欢

Oscp raven2 target penetration process

Mise en œuvre d’une fonction complexe d’ajout, de suppression et de modification basée sur jeecg - boot

中英对照:You can do this. Best of luck祝你好运

Redis core technology and basic architecture of actual combat: what does a key value database contain?

org. activiti. bpmn. exceptions. XMLException: cvc-complex-type. 2.4. a: Invalid content beginning with element 'outgoing' was found

Cobalt Strike特征修改

Summary of leetcode's dynamic programming 4

MySQL5.72.msi安装失败

Construction and integration of Zipkin and sleuth for call chain monitoring

私人云盘部署
随机推荐
MFC关于长字符串unsigned char与CString转换及显示问题
Convert the array selected by El tree into an array object
MFC on the conversion and display of long string unsigned char and CString
模拟卷Leetcode【普通】1447. 最简分数
Use shortcut LNK online CS
模拟卷Leetcode【普通】1218. 最长定差子序列
论文翻译英译中,怎样做翻译效果好?
模拟卷Leetcode【普通】1314. 矩阵区域和
oscp raven2靶机渗透过程
【MQTT从入门到提高系列 | 01】从0到1快速搭建MQTT测试环境
Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
How to do a good job in financial literature translation?
英语论文翻译成中文字数变化
Wish Dragon Boat Festival is happy
CS certificate fingerprint modification
Simulation volume leetcode [general] 1447 Simplest fraction
The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
删除外部表源数据
Py06 字典 映射 字典嵌套 键不存在测试 键排序