先有两张表,结构如下: table1 id ip time table2 id ipnum time 我想把table1中相同ip在同一天内的数量插入到table2
如下: table1 id ip time 0 11.11 2005-02-13 1 22.33 2005-02-13 2 11.11 2005-02-13 3 22.33 2005-02-13
table2 id ip ipnum time 0 11.11 2 2005-02-13 1 22.33 2 2005-02-13
请问SQL语句如何实现 select ip,time,count(*) from tb1 group by ip,time insert into tb2 select min(id),ip,count(*),time from tb1 group by ip,time SQL code: update t2 set t2.ipnum=t2.ipnum+isnull(t1.cnt,0) from table2 t2 left join (select ip,convert(varchar(10),[time],120) as [time],count(1) as cnt from table1 group by ip,convert(varchar(10),[time],120)) t1 on t1.ip=t2.ip and t1.[time]=convert(varchar(10),t2.[time],120)