日期:2014-05-17 浏览次数:20643 次
select distinct x.city,(select count(*)
from product y
where x.cid = y.cid)
from company x
select distinct x.city,(select count(*)
from product y, company z
where z.cid = y.cid and z.city = x.city)
from company x
drop table Product,Company
create table Product(pname varchar(100), price int, cid int)
create table Company(cid int,cname varchar(100),city varchar(100))
insert into Product values ('gizmo', 100, 1);
insert into Product values('powergizmo', 200, 1);
insert into Product values('iStuff', 500, 2);
insert into Product values('gadget', 300, 3); --修改cid为3
insert into Product values('powergadget', 400, 4); --修改cid为4
insert into Company values(1,'GizmoWorks','San Jose');
insert into Company values(2,'BigCompany','Boston');
insert into Company values(3,'PowerWorks','Seattle');
insert into Company values(4,'PowerWorks','Seattle'); --增加一条
select distinct x.city,(select count(*)
from product y