2

假设在表 A 中有很多行,列值为 a、b、c、d。

其中,我想要列值为“c”的 10 行,同时还计算列值为“c”的行总数。

我试过了:

select count(*),* from A where column like 'c'; (without limit)

select count(*),* from A where column like 'c' limit 10;

这甚至可能吗?还是我必须发出两个查询。

4

1 回答 1

1
SELECT n.*, AA.cnt 
FROM nei_product_background_category c
    INNER JOIN nei_backgrounds n ON n.background_id = c.background_id
    INNER JOIN ( 
        SELECT cc.product_id, COUNT(*) AS cnt 
        FROM nei_product_background_category cc
                    INNER JOIN nei_backgrounds nn ON nn.background_id = cc.background_id
        GROUP BY cc.product_id
    ) AA ON c.product_id = AA.product_id
WHERE
    c.product_id = 578
LIMIT 10
于 2013-02-17T16:23:57.840 回答