2. MySQL语句

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
RDS MySQL DuckDB 分析主实例,集群系列 8核16GB
简介: 2. MySQL语句

选择语句

sql

复制代码

use sql_store;
select *
from customers;
-- where customer_id = 2
-- order by points
select 
  last_name,
    first_name,
    points,
    points + 10,    -- 各种运算都可以
    (points + 10) * 100 as 'discount factor'    -- 起别名,有空格加单引号
from customers;
select distinct state   -- distinct 不重复字段 
from customers;
-- return all the products
-- name
-- unit price
-- new price (unit price * 1.0)
select name,unit_price,unit_price * 1.1 as new_price
from products;

where语句及相关

sql

复制代码

-- 比较符号
select *
from customers
where points > 3000 and state <> 'TX' or points = 3000 and state = 'TX';    
select * 
from ordes
where order_date >= '2019-01-01';
-- not
select * 
from ordes
where not state = 'IL';
select *
from order_items
where order_id = 6 and unit_price * quantity > 30;
-- in 范围
select *
from customers
where state not in ('VA','TX');     
-- between
select * 
from customers
where birth_date between '1990-01-02' and '2000-01-03';
-- like
-- %是*
-- _是?
select *
from customers
where last_name like '%b%' and 
    address not like '%trail%';
      
-- regexp 正则表达式
-- ^ 表示开始
-- $ 表示结束
-- | 逻辑或
-- [abcd]
-- [a-f]
select * 
from customers
where last_name like '%field%' and
    last_name regexp 'field' or
      last_name regexp '^field|mac|rose' or   -- 以field开头或者包含mac或rose
      last_name regexp '[a-h]e';
-- is null
select *
from customers
where phone is null;
-- order by
select *
from customers
order by state desc,first_name;
select birth_date, first_name, last_name, 10 as points
from customers
order by 1,2;   -- 相对顺序,从1开始
SELECT *,quantity * unit_price AS total_price
FROM order_items
WHERE order_id = 2
ORDER BY total_price DESC;
-- limit 限制数量
-- offset 偏移量
-- 可以结合使用page
select *
from customers
limit 3
offset 3

创建数据库

ini

复制代码

CREATE DATABASE 数据库名;

DELETE 语句

sql

复制代码

DELETE FROM table_name [WHERE Clause]
  • 如果没有指定 WHERE 子句,MySQL 表中的所有记录将被删除。
  • 你可以在 WHERE 子句中指定任何条件
  • 您可以在单个表中一次性删除记录。


相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
SQL 关系型数据库 MySQL
【MySQL】根据binlog日志获取回滚sql的一个开发思路
【MySQL】根据binlog日志获取回滚sql的一个开发思路
|
设计模式 安全 编译器
C++设计手段的智慧:从基础到前沿
C++设计手段的智慧:从基础到前沿
273 1
|
边缘计算 缓存 Kubernetes
阿里云江岑:云原生在边缘形态下的升华
5月20-22日,第十三届中国系统架构师大会(SACC2021)在云端进行网络直播,主题为“数字转型、架构重塑”。阿里云边缘云原生技术专家江岑,分享了阿里云在边缘云原生的探索实践,并从应对技术挑战与系统架构设计等方面阐述产品核心竞争力,以创新技术驱动业务发展。
1566 0
阿里云江岑:云原生在边缘形态下的升华
|
5天前
|
云安全 人工智能 自然语言处理
|
9天前
|
人工智能 Java API
Java 正式进入 Agentic AI 时代:Spring AI Alibaba 1.1 发布背后的技术演进
Spring AI Alibaba 1.1 正式发布,提供极简方式构建企业级AI智能体。基于ReactAgent核心,支持多智能体协作、上下文工程与生产级管控,助力开发者快速打造可靠、可扩展的智能应用。
864 26
|
4天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
450 4
|
6天前
|
机器学习/深度学习 人工智能 数据可视化
1秒生图!6B参数如何“以小博大”生成超真实图像?
Z-Image是6B参数开源图像生成模型,仅需16GB显存即可生成媲美百亿级模型的超真实图像,支持中英双语文本渲染与智能编辑,登顶Hugging Face趋势榜,首日下载破50万。
384 18
|
12天前
|
数据采集 人工智能 自然语言处理
Meta SAM3开源:让图像分割,听懂你的话
Meta发布并开源SAM 3,首个支持文本或视觉提示的统一图像视频分割模型,可精准分割“红色条纹伞”等开放词汇概念,覆盖400万独特概念,性能达人类水平75%–80%,推动视觉分割新突破。
825 59
Meta SAM3开源:让图像分割,听懂你的话