我还没有足够的SQL查询构建经验。 我有一张2桌:
producers (
prod_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
prod_title text
);
models (
prod_id NOT NULL,
model_name text,
FOREIGN KEY (prod_id) REFERENCES producers(prod_id)
);
如何获取表格表格:
column1.............column2
producer1...........the amount of models producers1
producer2...........the amount of models producers2
...
producerN...........the amount of models producerN
答案 0 :(得分:1)
根据您对表的描述,您似乎想要使用count
函数,并按生产者ID分组,请尝试以下操作:
select p.prod_title, count(*)
from producers p
join models m on p.prod_id = m.prod_id
group by p.prod_id