下面的语句是从products表中获取所有不重复的id。有没有办法得到这个sql语句输出的行总数?

select min(product_id) from products
where market_code = 'germany'
group by product_code

示例表数据:
product_id   market_code   product_code
   1            uk             AAA
   1            uk             AAA
   1            uk             AAA
   2           germany         BAA
   2           germany         BAA
   3            uk             BAA

谢谢

最佳答案

您只需执行以下操作:

SELECT COUNT(*)
FROM
(
    select min(product_id) from products
    where market_code = 'germany'
    group by product_code
) AS t;

关于mysql - 无论如何,使用Min()时是否要执行Count()?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19619224/

10-11 03:36