1

基本上我有一堆属于经销商的汽车,经销商有一个小组。经销商表具有 GROUP.ID,组表具有组名。一个集团有多个经销商

所以我想计算每组有多少辆车。

我正在使用这个自动取款机

select  
  (select GROUP_NAME from "GROUP" where "GROUP".GROUP_ID = "DEALER"."GROUP_ID" ),
  "DEALER"."GROUP_ID" as "DEALER GROUP ID",
  "DEALER"."DEALER_NAME" as "DEALER DEALER NAME",
  "CAR"."CAR_DEALER" as "CAR DEALER"         
from 
  "CAR"
INNER JOIN 
  DEALER
ON 
  "DEALER"."DEALER_NAME" ="CAR"."CAR_DEALER"

我试过使用group_bycount但我似乎无法让它工作

4

1 回答 1

5
select
  g.GROUP_NAME,
  g.GROUP_ID,
  count(*) as CAR_COUNT
from
  GROUP g
  inner join DEALER d on d.GROUP_ID = g.GROUP_ID
  inner join CAR c on c.DEALER_ID = d.DEALERID
group by
  /* Also add here all field you want to select from GROUP */
  g.GROUP_NAME,
  g.GROUPID
于 2012-04-18T22:46:25.953 回答