This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 各位高手高手高高手,SQL的Query问题请教,请进:Table C: Area,Date
Table R: Zip, ScheduledDate(每个Record都有相应ScheduledDate和所在Zip)
Table D: Zip,Area(每个Area有若干zip)
我需要一个新的table,选Table C的全部,和一个新的Colum,这个Column里Count Table R里边,有多少个与Table C中相应Area相同而且Date相同的纪录。
我说明白了吗?
逻辑我倒是挺明白,写出来老不对。谢谢回复!鞠躬!
-goldsky(泥锅泥碗泥滚蛋);
2004-2-11
{336}
(#1600244@0)
-
帮帮忙吧~~~~~~~~
-goldsky(泥锅泥碗泥滚蛋);
2004-2-11
(#1600304@0)
-
分2步作1。 create view q1 as select d.area,r.dt from d,r where d.zip=r.zip
2. select c.*,q1.* from c left join q1 on c.area=q1.area and c.dt=q1.dt
不知道我理解得对不对,这是在SQL Server下作的
-zxcvb(朝天椒);
2004-2-11
{188}
(#1600318@0)
-
呵呵,不对,你是要COUNT啊,再想想
-zxcvb(朝天椒);
2004-2-11
(#1600323@0)
-
改一下create view q1 as
select d.area,r.dt,count(*) as ct from d,r where d.zip=r.zip group by d.area,r.dt
go
select c.*,q1.ct from c left join q1 on c.area=q1.area and c.dt=q1.dt
-zxcvb(朝天椒);
2004-2-11
{179}
(#1600341@0)
-
谢谢。我刚才回了你的帖子,怎么没了??
-goldsky(泥锅泥碗泥滚蛋);
2004-2-11
(#1600356@0)
-
select c.area,c.date,count(*) from c,r,d where c.area=d.area and d.zip=r.zip and c.date=r.date group by c.area,c.date.
-easyway(漂流);
2004-2-11
(#1600320@0)
-
感激涕零!鼻涕横流。。。。对了!谢谢!
-goldsky(泥锅泥碗泥滚蛋);
2004-2-11
(#1600334@0)
-
I'm just wondering why you don't come out to say 'xiexie',haha kidding!
-easyway(漂流);
2004-2-11
(#1600340@0)
-
select c.area, c.date, count(r.zip) count_zip
from table_c c, table_r r, table_d d
where c.area = d.area
and d.zip = r.zip
and c.date=r.date1
group by d.area
-mustang(mustang);
2004-2-11
(#1600354@0)
-
谢了,和楼上一样,你门都是高手哪!
-goldsky(泥锅泥碗泥滚蛋);
2004-2-11
(#1600361@0)