首页 > 数据库 >mysql常用查询

mysql常用查询

时间:2023-10-16 16:36:15浏览次数:46  
标签:常用 NAME COLUMN 查询 mysql TABLE where id schema

1、Mysql查询某个表的字段名

select COLUMN_NAME from information_schema.COLUMNS where table_name = 'business_info';

 

2、生成数据字典
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,COLUMN_COMMENT from information_schema.columns where TABLE_SCHEMA='dida'

 

 
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,COLUMN_COMMENT from information_schema.columns where TABLE_NAME='business'

 

  3、多表更新
update settlement s
inner join business_bank b on
b.business_id = s.business_id
set s.status = 0    
where s.status = 1 and s.oid_paybill is null and b.pay_online = 1

 

update table1 t1,table2 t2 
set t1.name = t2.name where t1.id = t2.id

 

  4、多表删除
delete ir from 
business_interest_rate ir
left join business_base b on ir.business_id = b.id
left join business_head bh ON b.business_parent_id = bh.id
left join business_industry i ON i.id = bh.industry
where b.id is null

 

5、mysql中的先排序后分组   gp比较集中时使用(一个gp下有好多好多记录):
SELECT a.id,a.sort,a.gp,a.name FROM (  
    SELECT * FROM sort_group ORDER BY sort DESC  limit 100000
) a  
GROUP BY a.gp 

 


gp比较分散时使用(就是一个gp下只有几条记录):
SELECT * FROM `sort_group` 
WHERE id IN 
(SELECT SUBSTRING_INDEX(GROUP_CONCAT(id ORDER BY sort DESC),',',1) FROM sort_group GROUP BY gp);
 

 

  /*查询表的字段名*/
select COLUMN_NAME from information_schema.COLUMNS where table_name = 'orders';

 

  /*生成数据字典*/
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,case when IS_NULLABLE = 'NO' then '否' else '是' end,COLUMN_COMMENT from information_schema.columns where TABLE_SCHEMA='dida'
 

 

select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,COLUMN_COMMENT from information_schema.columns where TABLE_NAME='business'
 

 

select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,case when IS_NULLABLE = 'NO' then '是' else '否' end,COLUMN_DEFAULT,case when COLUMN_KEY = 'PRI' then '主键' else '' end,COLUMN_COMMENT  from information_schema.columns where TABLE_SCHEMA='test_police_zhxjg'

 

  /*取万*/
select round(sum(money)/10000+0.00000001,2) as total_money  from orders

 

  /*查询没有主键的表*/
select table_schema,table_name from information_schema.tables 
where (table_schema,table_name) not in(
    select distinct table_schema,table_name from information_schema.columns where COLUMN_KEY='PRI'    
)
and table_schema not in (
    'sys','mysql','information_schema','performance_schema'
);

 

 

标签:常用,NAME,COLUMN,查询,mysql,TABLE,where,id,schema
From: https://www.cnblogs.com/anquing/p/17767667.html

相关文章

  • Linux部署MySQL过程记录
    一.Linux版本cat/proc/versioncat/etc/redhat-release 二.MySQL安装2.1检查是否已安装MySQLrpm-qa|grep-imysql 2.2解压安装文件到指定文件夹tar-xvf对应mysql的安装包名字.tar-c解压到指定目录下tar-xvfmysql-5.7.43-1.el7.x86_64.rpm-bundle.tar-C......
  • HDPE-高密度双壁波纹管材常用的应用领域有哪些?
    HDPE-高密度双壁波纹管材是一种由高密度聚乙烯制成的管材,具有特殊的波纹结构。HDPE-高密度双壁波纹管材常用的应用领域有:市政工程:可用于排水、排污管。建筑工程:用于建筑物雨水管、地下排水管、排污管、通风管。电气工程:可用于各种动力电缆的保护管公路、铁路通讯:用于通讯电缆、光缆......
  • SQL语句的基本使用5-多值子查询
    这个作业属于哪个课程https://edu.cnblogs.com/campus/uzz/cs3这个作业要求在哪里https://edu.cnblogs.com/campus/uzz/cs3/homework/13074这个作业的目标SQL语句的基本使用5-多值子查询1.在student_info表中查找与“刘东阳”性别相同的所有学生的姓名、出生日......
  • MySQL锁表问题
    今天遇到一个情况,一条SQL语句执行提示如下异常。Lockwaittimeoutexceeded;tryrestartingtransaction翻译一下是说,获取锁超时,尝试重新启动事务。翻译一下就是当我们申请对表进行加锁时,另外一个事务已经对这个表加了锁,经过一段时间等待后,我们的事务依然没有获取到锁,所以提......
  • Java 常用中间件
    Java常用中间件1、网关Nginx、Kong、Zuul、Gateway2、缓存Redis、MemCached、OsCache、EhCache3、搜索ElasticSearch、Solr4、熔断Hystrix、resilience4j5、负载均衡DNS、F5、LVS、Nginx、OpenResty、HAproxy6、注册中心Nacos、Eureka、Zookeeper、Redis、Etcd、Cons......
  • yarn的常用命令
    yarn的常用命令:yarn-v//查看yarn版本yarnconfiglist//查看yarn配置yarnconfiggetregistry//查看当前yarn源//修改yarn源(此处为淘宝的源)yarnconfigsetregistryhttps://registry.npm.taobao.org//yarn安装依赖yarnadd包名//局部安......
  • MySQL的InnoDB索引失效的场景和优化
    康师傅YYDS索引失效案例索引最好是全值匹配。where条件中等值比,同时where的条件一起创建联合索引。最佳左前缀如果有一个联合索引,要想使用到,需要从联合索引的最左边的字段开始写,一点一点的写上。主键插入顺序在InnoDB中,使用自增的主键。避免索引页面分裂计算、函数、类型......
  • ubuntu 22.04安装mysql5.7
    ubuntu22.04系统安装mysql5.7一、查看系统默认安装的数据库版本apt-getupdateapt-cachepolicymysql-serverubuntu20.04自带的版本是8.0.34,而我们需要安装mysql5.7的版本就需要换源二、更换apt源1.备份原来的source文件cp/etc/apt/sources.list/etc/apt/sources......
  • 大集合里查询数据-布隆过滤器
    1.问题场景有100亿个url被加入了黑名单,现在提供一个url要去判断是否属于黑名单。也就是一个很简单的一个东西是否属于一个集合的问题。一般来说用set就能解决这种问题,但是由于url数目太多,内存中无法开辟一个这么大的空间去存放所有url,这个时候就需要我们去使用一种结构,去减少状......
  • .NET 一些常用的类型转换扩展
    ///<summary>///转换扩展类///</summary>publicstaticpartialclassExtensions{#region转换为long///<summary>///将object转换为long,若转换失败,则返回0。不抛出异常。///</summary>///&l......