我正在尝试通过主键合并2个表,但另外还要添加一个表的选择计数。我试过了
Select a.ram as ram1, b.ram as ram2 from a,b
现在我要添加b的count(*) 不工作。
Select
(Select count(*) from b inner join a on a.ram=b.ram as numberbids),
A.ram as ram1, b.ram as ram2 from a,b;
给我正确的列但是计算了b的所有出价,而不是公羊。
有人可以帮忙吗? 感谢
我得到了: 表a:
ram
x
y
表b:
z
ram
bids
我想:
ram1 ram2 numberofbids
我希望这有帮助吗?我是SQL的新手
答案 0 :(得分:0)
试试这个:
select a.ram,b.ram,count(*) as numberbids
from b inner join a on a.xy=b.xy
group by a.ram,b.ram
如果您不想INNER JOIN
,则需要跨产品,然后使用CROSS JOIN
:
select a.ram,b.ram,count(*) as numberbids
from b cross join a
group by a.ram,b.ram