2. MySQL语句

简介: 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;
相关文章
|
9天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17344 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
3天前
|
人工智能 安全 网络安全
|
6天前
|
云安全 数据采集 人工智能
|
7天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1332 3
|
14天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2408 7
|
19天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
3888 22
|
20天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是DeepSeek AI开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、跑命令、处理表格、联网搜索等操作。免费开源,兼容Windows/macOS/Linux,提供桌面端与网页端,可灵活安装插件扩展能力。

热门文章

最新文章