问题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';
select name,count(*) from a,b where a.moduleid=b.moduleid
and a.forgid='E' group by name
你要是不建主键多少个都可以有