首页 > 数据库 >MySQL操作 UPDATE、SELECT、UNION、IN、DISTINCT

MySQL操作 UPDATE、SELECT、UNION、IN、DISTINCT

时间:2024-06-10 11:33:51浏览次数:11  
标签:name UNION age UPDATE sex DISTINCT user where select

update 更新

所有人的年龄加一:update user set age=age+1;
只更新某个: update user set age=age+1 where name='zhang san';

select查询

select * from user;//一般不建议使用通配符
select name,age,sex from user;//根据键查找
select name,age,sex from user where sex='M' and age>=20 and age<=25;
select name,age,sex from user where sex='M' and age between 20 and 25;
select name,age,sex from user where sex='W' or age>=22;
select name,age,sex from user where name like "zhang%";
select name,age,sex from user where name is not null;

联合查询 UNION

SELECT expression1, expression2, ... expression_n
FROM tables[WHERE conditions]
UNION [ALL | DISTINCT]
SELECT expression1, expression2, ... expression_n
FROM tables[WHERE conditions]

union默认去重,不用修饰distinct,all表示显示所有重复值

例如:

select name,age,sex from user where age >=21 union all select name,age,sex from user where sex='M';

注意:between是[ ]。like 部分匹配不加=,null not null使用is

带in子查询

select name,age,sex from user where age in (20,21);
select name,age,sex from user where age not in (20,21);

在一个区间内查找IN,不在这个区间内查找NOT IN.

去重

将年龄拿出来去重显示: select distinct age from user;
在这里插入图片描述

标签:name,UNION,age,UPDATE,sex,DISTINCT,user,where,select
From: https://blog.csdn.net/m0_73537205/article/details/139554556

相关文章

  • SQL Server 2022 RTM 最新累积更新:Cumulative Update #13 for SQL Server 2022 RTM
    SQLServer2022RTM(最新累积更新)-基于Azure的持续性能和安全创新CumulativeUpdate#13forSQLServer2022RTM请访问原文链接:https://sysin.org/blog/sql-server-2022/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgSQLServer2022现已普遍可用2022......
  • hive性能优化系列-distinct-有限key
    案例方式1使用groupbyselects_age,count(1)from(selects_agefromstudent_tb_orcgroupbys_age)b方式2使用distinctselects_age,count(distincts_age)fromstudent_tb_orc分析数据量特别大方式1的代码在数据量特别大的情况下能够有效避免Reduce端的数据......
  • 【VMware vSphere】安装配置Update Manager Download Service(UMDS)作为 vLCM 的下载存
    VMwarevSphereUpdateManagerDownloadService(UMDS)是vSphereLifecycleManager(vLCM)的可选模块。我在之前文章中提到这个功能,当vSphere环境能够连接Internet时,我们可以使用vLCM的在线Internet下载源获取修补程序,当vSphere环境不能连接Internet时,您可以在您的......
  • Mysql基础教程(14):UNION
    MySQLUNION的用法与实例在本文中,我们讨论在MySQL中对两个结果集进行UNION运算,以及UNION运算的规则。在MySQL中,UNION操作符是一个集合操作符,它用于合并【2个结果集】中的所有的行。SQL标准中定义了3个集合操作符:UNION,INTERSECT和MINUS。目前MySQL......
  • Python - Django - MySQL #need to add distinct() after select_related().distinct(
    所以这是ads/views.py还有ads/models.py、ads/forms、ads/urls.py和其他文件,但评分器抱怨的是这个views.py...检索到3806个HTML字符测试已完成:在页面顶部发现菜单栏搜索"HHGTTG_421717639962"时发现多个广告。您可能需要在views.py中的select_related().di......
  • VMware vSphere 8.0 Update 3 下载 - 企业级工作负载平台
    VMwarevSphere8.0Update3下载-企业级工作负载平台ESXi8.0U3&vCenterServer8.0U3请访问原文链接:https://sysin.org/blog/vmware-vsphere-8-u3/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org企业工作负载引擎vSphere获得企业工作负载引擎的强大功能。......
  • SQL--union用法
    UNION 是SQL中用于合并两个或多个 SELECT 语句结果集的操作符。这些 SELECT 语句必须选择相同数量的列,并且这些列的数据类型必须兼容。UNION 会自动去除结果集中的重复行,而如果你想要保留重复行,可以使用 UNIONALL。 UNION 的基本语法:制代码SELECT column_na......
  • AOP简化公共属性create_time,create_user,update_time,update_user记录的重复代码
    处理这些公共字段,需要在每一个业务方法中进行操作,编码相对冗余、繁琐使用AOP切面编程,实现功能增强,来完成公共字段自动填充功能。1.2实现思路在实现公共字段自动填充,也就是在插入或者更新的时候为指定字段赋予指定的值,使用它的好处就是可以统一对这些字段进行处理,避免了重......
  • 日常Bug排查-MVCC和for update混用导致读数据不一致
    日常Bug排查-MVCC和forupdate混用导致读数据不一致前言日常Bug排查系列都是一些简单Bug的排查。笔者将在这里介绍一些排查Bug的简单技巧,同时顺便积累素材。Bug现场又是喜闻乐见的读数据不一致的问题。这次的问题是这样,业务在一个事务中更新A和B两个表的两个数据。但是在另一......
  • twrp 刷机包 刷入magisk.zip 构造原理 关键词:META-INF update-binary updater-script
    https://blog.csdn.net/yuleslie/article/details/8718385  #MAGISK##############################################MagiskFlashScript(updater-script)#bytopjohnwu############################################################Preparation#########......