JojoMiss

疯魔jojo的后花园

导航

SQL相关笔记-不常用 容易忘记的一些语法规则记录

1. 查下表中只有一条的数据

SELECT userId,count(userId) FROM 表名 GROUP by userId

2. 根据userId去重

select distinct userId from 表名

3. 查询数据库中含有某个字段的所有表名

select DISTINCT TABLE_NAME from information_schema.`COLUMNS` 
where TABLE_SCHEMA = '数据库名称' and COLUMN_NAME = '需要查的字段名称' 
and TABLE_NAME not like 'vm%'

select name from sysobjects where xtype='U' and id in
 (select id from syscolumns where name='已知字段名')

4. 获取当前时间几种方式

日期时间格式

now() -- 2020-12-03 11:48:20.0

获取当前毫秒时间戳,如果是秒的话 就不要后面的“*1000”

UNIX_TIMESTAMP(now())*1000

5. 查询表中有重复记录的数据

select * from 数据表 WHERE 重复记录字段 in ( select 重复记录字段 from  数据表 group by 重复记录字段 having count(重复记录字段)>1)

6.已知表名的部分字符,查询所有符合的表

select name from sysobjects where name like '%已知字符%'

 

posted on 2024-04-02 22:09  幽忧一世  阅读(1)  评论(0编辑  收藏  举报

⭐️CSDN 我的文章列表⭐️
⭐WEIBO 微博首页⭐️
⭐园子 我的院子⭐️