注册 登录
编程论坛 SQL Server论坛

求個語句

cyh0519 发布于 2007-12-14 14:03, 757 次点击
我有2個表其中有一列是相關聯 比如:
TABLE1有下面几列
ID  NAME  DATE  PREID
TABLE2有下面几列
ID  XSNAME  REDATE  
我要根據輸入一個條件符合TABLE1中的DATE然後查出TABLE2的REDATE再把這個數據插入TABLE3中
這要什麼寫
拜託大家啊
5 回复
#2
cyh05192007-12-14 14:12
REDATE求出計總的筆數再插入TABLE3中的COUNT列
#3
purana2007-12-14 15:15
insert into tb3 select tb1.* from tb1,tb2 where tb1.id=tb2.id and tb2.REDATE='2007-10-01'
#4
madpbpl2007-12-14 15:39
如果插入tb3的仅仅是redate列,而不是所有tb1的数据呢?
#5
purana2007-12-14 16:16
insert into tb3(redate) select tb2.redate from tb1,tb2 where tb1.id=tb2.id and tb2.REDATE='2007-10-01'


jet-sql也差不多.
#6
madpbpl2007-12-14 16:32
insert into table3
(id,count)
select id,redate
from table2 b
where b.redate in (select date from table1)
我是这样写的,但是如果只插入count,不插入id,就会报错。
哦,可能是id类型是int,不能为null。
1