2

代码:

SELECT ta.name AS ta_name,
       ta.unit  AS ta_unit,
       ta.id_producer_goods AS ta_id_producer_goods
    FROM   Table ta
    WHERE  id_city = '24'
           AND id_firm = '22131'
           AND id_service = '5'

在选择中,我需要按 ta_name 分组获取行(结果应仅包括唯一的 ta_name)并获取所有表中每个唯一 ta_name 的计数。

怎么做?

4

2 回答 2

1

似乎太简单了——但这就是我理解你所需要的。

SELECT ta.name AS ta_name,
  ta.unit              AS ta_unit,
  ta.id_producer_goods AS ta_id_producer_goods, COUNT(*)
FROM TABLE ta
WHERE id_city  = '24'
AND id_firm    = '22131'
AND id_service = '5'
GROUP BY ta.name, ta.unit, ta.id_producer_goods
于 2013-09-26T01:48:13.920 回答
0

我认为这可能会有所帮助

SELECT DISTINCT COUNT(ta.name)
            ,   ta.name AS ta_name
            ,   ta.unit AS ta_unit
            ,   ta.id_producer_goods AS
                ta_id_producer_goods
FROM [table] ta
WHERE id_city = '24'
    AND id_firm = '22131'
    AND id_service = '5'
GROUP BY
        ta.name
    ,   ta.unit
    ,   ta.id_producer_goods
于 2013-09-26T02:24:38.010 回答