当前位置:网站首页>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【普通】1091. 二进制矩阵中的最短路径
- The pit encountered by keil over the years
- 【MQTT从入门到提高系列 | 01】从0到1快速搭建MQTT测试环境
- Biomedical English contract translation, characteristics of Vocabulary Translation
- Simulation volume leetcode [general] 1219 Golden Miner
- How much is it to translate Chinese into English for one minute?
- 模拟卷Leetcode【普通】1143. 最长公共子序列
- Apple has open source, but what about it?
- Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order
猜你喜欢
Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
Private cloud disk deployment
E-book CHM online CS
Technology sharing | common interface protocol analysis
LeetCode 731. My schedule II
专业论文翻译,英文摘要如何写比较好
Construction and integration of Zipkin and sleuth for call chain monitoring
LeetCode 739. Daily temperature
MySQL is sorted alphabetically
Basic knowledge of MySQL
随机推荐
MFC on the conversion and display of long string unsigned char and CString
leetcode 24. 两两交换链表中的节点
LeetCode 731. My schedule II
org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis
LeetCode 739. Daily temperature
模拟卷Leetcode【普通】1405. 最长快乐字符串
今日夏至 Today‘s summer solstice
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
关于新冠疫情,常用的英文单词、语句有哪些?
The internationalization of domestic games is inseparable from professional translation companies
Technology sharing | common interface protocol analysis
Transfert des paramètres de la barre d'adresse de la page de liste basée sur jeecg - boot
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
Biomedical localization translation services
Career advancement Guide: recommended books for people in big factories
ECS accessKey key disclosure and utilization
E-book CHM online CS
论文翻译英译中,怎样做翻译效果好?