遇到一个更一个
<1>插入一条数据
1insert into user(username, userage) values("小明", 18)
<2>统计年月
2018-08: CONVERT(VARCHAR(7),a.ddate,120)
YEAR MONTH
2018 8
YEAR(a.ddate) as YEAR,MONTH(a.ddate) as MONTH
<3>把同一张表满足条件的赋值给表中另一行的字段值(一行中的一个数据也行)
update a
set repFile=b.repFile
from sys_report a,sys_report b
where a.id=b.id-1 and a.id=362
<4>查询两个表的数据是否一致,不一致的数据显示出来
select * from sys_report1 a where not exists(select * from sys_report b where a.repCName=b.repCName)
<5>根据<4>把不一致数据插入少的一张表中
Insert into sys_report(Id,repName,repFile,repCName,category,styleName,id1,id2)
select Id,repName,repFile,repCName,category,styleName,id1,id2 from sys_report1 a where not exists(select * from sys_report b where a.repName=b.repName)
<6> 表中找出重复的数据
select * from 表名
where 字段 in (select 字段 from 表名 where 条件 group by 字段 having count
(字段) > 1)
distinct
<7>几个时间的最大时间
select convert(char(10),time,120) 日期,
(case when MAX(A)>MAX(B) and MAX(A)>MAX(C) then MAX(A)
when MAX(B)>MAX(A) and MAX(B)>MAX(C) then MAX(B)
when MAX(C)>MAX(A) and MAX(C)>MAX(B) then MAX(C)
end)ABC最大值
from ttt group by convert(char(10),time,120)
select * from ttt