当前位置:网站首页>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
边栏推荐
- 在uni-app中使用腾讯视频插件播放视频
- Lecture 8: 1602 LCD (Guo Tianxiang)
- Modify the list page on the basis of jeecg boot code generation (combined with customized components)
- Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis
- Postman core function analysis - parameterization and test report
- Delete the variables added to watch1 in keil MDK
- Biomedical English contract translation, characteristics of Vocabulary Translation
- 模拟卷Leetcode【普通】1314. 矩阵区域和
- Office-DOC加载宏-上线CS
- Financial German translation, a professional translation company in Beijing
猜你喜欢
University of Manchester | dda3c: collaborative distributed deep reinforcement learning in swarm agent systems
How much is the price for the seal of the certificate
Wish Dragon Boat Festival is happy
Technology sharing | common interface protocol analysis
E-book CHM online CS
基于JEECG-BOOT的list页面的地址栏参数传递
What are the commonly used English words and sentences about COVID-19?
CS-证书指纹修改
MySQL is sorted alphabetically
Data type of MySQL
随机推荐
Wish Dragon Boat Festival is happy
Office-DOC加载宏-上线CS
Manage configuration using Nacos
How much is it to translate Chinese into English for one minute?
Black cat takes you to learn UFS Protocol Part 8: UFS initialization (boot operation)
leetcode 24. 两两交换链表中的节点
Qt:无法定位程序输入点XXXXX于动态链接库。
国产游戏国际化离不开专业的翻译公司
Basic knowledge of MySQL
Simulation volume leetcode [general] 1219 Golden Miner
模拟卷Leetcode【普通】1405. 最长快乐字符串
Advanced MySQL: Basics (1-4 Lectures)
删除外部表源数据
Delete the variables added to watch1 in keil MDK
keil MDK中删除添加到watch1中的变量
字幕翻译中翻英一分钟多少钱?
在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
Simulation volume leetcode [general] 1109 Flight reservation statistics
专业论文翻译,英文摘要如何写比较好
Traffic encryption of red blue confrontation (OpenSSL encrypted transmission, MSF traffic encryption, CS modifying profile for traffic encryption)