我工作中常用到的sql
下面是我工作中常用的sql,每次都是修修改改多次使用
插入
- insert into 库名.表名
(co,po,date,type,name,tuser)(字段名)
values(‘1111’,‘1111’,‘20200918’,‘I’,‘名字’,‘XXX’)(插入的值)
查询
- select * from 库名.表名 where 字段名 =‘111111’ and 更新时间 >‘2020-07-01’
- select * FROM 库名.表名 where PREM_CD=‘H’ and po_cd =‘1’ AND DRY_ID
=‘Bttt’ AND L_ID IN ( SELECT L_ID FROM 库名.表名 WHERE GT_ID LIKE ‘%11000000%’) ORDER BY EFF_DT DESC LIMIT 100 - select * FROM 库名.表名 where T_CD=‘00’ and at_cd =‘10’ AND 、RY_ID
=‘Tyyyy’ ORDER BY FF_DT DESC LIMIT 100 - SELECT * FROM 库名.表名 WHERE CI_ID IN ( select ci_id from 库名.表名 where
po_cd = ‘I’ and klo_id =‘1111111’ )
更新
- update 表名 set adaddrd=‘以一路速度速度阿三193号’ where adpolnum=‘111111’
(切记加where条件) - Update 表名 Set COMPNUM=‘111111’ Where CO=‘111’ and
CONUM=‘111111111’ and RIDNUM=‘01’ and LAT=‘P’
sql语句还是需要结合自己的使用场景来写,没办法来总结,因为我们每次查询的需求都是不一样的,但是基本的
介绍其他的sql
SQL分类
DDL—数据定义语言(Create,Alter,Drop,DECLARE)
DML—数据操纵语言(Select,Delete,Update,Insert)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
基本的sql语句
-
选择:select * from table1 where 条件
-
插入:insert into table1(field1,field2) values(value1,value2)
-
删除:delete from table1 where 条件
-
更新:update table1 set field1=value1 where 条件
-
排序:select * from table1 order by field1 desc
高级查询运算词
-
前10条记录
select top 10 * form table1 where 范围 -
包括所有在 TableA 中但不在 TableB和TableC 中的行并消除所有重复行而派生出一个结果表
(select a from
tableA ) except (select a from tableB) except (select a from tableC) -
随机取出10条数据
select top 10 * from tablename order by newid() -
列出数据库里所有的表名
select name from sysobjects where type=‘U’ -
去除查询结果的重复值
select distinct name from user -
sql语句删除姓名重复的数据
delete from user where name in (select name from user group by name having count(name) > 1) -
查询出了数据库中user表的重复数据
select * from user where name in (select name
from user group by name having count(name) > 1)