SQL数据库中两个表A,B存放内容不一样,需要关联两表查询数据.

2024-11-22 04:48:13
推荐回答(3个)
回答1:

问题1:E机构里面的每个名称下面有多少个价格,如果要制定某一个名称,可以在where条件中增加name最为条件:
select a.name , count(price) from a,b where a.mediid = b.mediid and a.forgid = b.forgid and a.forgid = 'E' group by a.name;
如果要去掉重复价格可以增加distinct,如下:
select a.name , count(distinct price) from a,b where a.mediid = b.mediid and a.forgid = b.forgid and a.forgid = 'E' group by a.name;
问题2:查询E机构下面,两个表中编号相同的项目
select count(name) from a,b where a.mediid = b.mediid and a.forgid = b.forgid and a.forgid = 'E';

回答2:

select name,count(*) from a,b where a.moduleid=b.moduleid
and a.forgid='E' group by name

回答3:

你要是不建主键多少个都可以有