1、数据操作

1.1、插入

1.2、删除

1.2.1、删除整个表数据

  1. // (清空表中的数据):删除内容、释放空间但不删除定义(保留表的数据结构)。与drop不同的是,只是清空表数据而已
  2. truncate table [talbeName]
  3. // truncate与不带where的delete :只删除数据,而不删除表的结构(定义)
  4. delete from dbo.Sys_Test

1.3、更新

1.4、查询

1.4.1、获取第一条记录

  1. select top 1 * from ems.d5000.semaphore where "date" between '2021-10-01' and '2021-10-31' order by "date" asc
  2. select * from ems.d5000.semaphore where "date" between '2021-10-01' and '2021-10-31' order by "date" desc limit 1

1.4.2 分组合并统计个数

  1. select
  2. sum(case when d.pri_flags='1' then d.num end) as acc
  3. ,sum(case when d.pri_flags='2' then d.num end)
  4. ,sum(case when d.pri_flags='3' then d.num end)
  5. ,sum(case when d.restrain_flag='0' and d.pri_flags='1' then d.num end)
  6. ,sum(case when d.restrain_flag='0' and d.pri_flags='2' then d.num end)
  7. ,sum(case when d.restrain_flag='0' and d.pri_flags='3' then d.num end)
  8. from (select b.pri_flags,a.restrain_flag,count(*) as num from HISDB.ALARM.YX_BW_2021_10 a,EMS.EMS.RELAYSIG b ,EMS.EMS.SUBSTATION c
  9. where a.yx_id&0xFFFF0000FFFFFFFF=b.id
  10. and c.id=a.st_id
  11. and c.bv_id='112871465677750274'
  12. and a.occur_time between '2021-10-03' and '2021-10-04' group by a.restrain_flag,b.pri_flags) as d

1.4.3、获取所有表名

  1. -- 获取数据库中的所有表名
  2. SELECT TABLE_NAME
  3. FROM information_schema.`TABLES`
  4. WHERE TABLE_SCHEMA="lms_job"

1.4.4、查询某个表的所有列

  1. -- 获取某个库的某个表的列属性
  2. SELECT *
  3. FROM information_schema.`COLUMNS`
  4. WHERE TABLE_SCHEMA="lms_job" and TABLE_NAME="lms_job_task"

2、索引

2.1、创建索引

  1. // 达梦数据库创建索引
  2. CREATE [UNIQUE] INDEX "date_index" ON "EMS"."D5000"."SEMAPHORE"("date");

2.2、删除索引

  1. // 达梦数据库
  2. DROP INDEX "EMS"."D5000"."seq_no_index";

3、函数

3.1、执行函数

  1. select round(1.1923,2);
  2. select ceil(1.1923);

3.2、时间函数


  1. select * from px_basesystem_fileservice.nfile_info_oss
  2. where STR_TO_DATE(upload_date,'%Y-%m-%d')=STR_TO_DATE(SYSDATE(),'%Y-%m-%d')

1、时间转字符串
STR_TO_DATE(SYSDATE(),'_%Y-%m-%d %H:%i:%s_')

2、重新格式化
DATE_FORMAT(date_add(sysdate(),interval -1 day),'%Y-%m-%d')