SQL小节
10 主键和外键关系一对多:
alter table temp1(层表)
Add constraint F_userId
foreign key(userId) references T_User(主表)(id)
11 多表联合查询
select row_number() over(order by t.registerdate desc) as num,t.occurrenceid,t.occurrencenum2,t.registerdate,b.occtype,t.AMOUNT,t.occtime,t.yr,t.zi,t.hao,t.step as step from occurrence t left join OCC_TYPE b on t.occtypeid=b.occtypeid where occurrenceid in(
select distinct occurrenceid from (
select a.occurrenceid from occ_roadloss a group by a.projid,a.occurrenceid having count(*)>1 union
select distinct occurrenceid from (select a.name,a.carno,a.occurrenceid,count(*) cnt from occ_party a group by a.name,a.carno,a.occurrenceid having count(*)>1) as proTable ) as tb)
group by:结合聚合查询分组 having相当于where作为条件查询 子查询的查时候 as 表名即可
12 要想修改自增列的值,好办,修改字段取消自增列,改好后,在恢复自增列,就ok了!