将查询转换为计数行

时间:2014-09-03 14:17:52

标签: mysql sql

如何转换此查询以获取行数?

SELECT IF(rz_price_grn != 0, rz_price_grn, ROUND(rz_price2 * currencies.`rate`)) AS `ssc_price`, rz_price_grn, rz_price2, IF(price IS NULL, 0, price) AS `goods_price`
FROM rz_price
LEFT JOIN currencies ON currencies.`name` = 'USD'
LEFT JOIN  goods ON goods.id = rz_price.`rz_art`
LEFT JOIN rz_archive ON rz_archive.rz_art  = rz_price.rz_art
WHERE
 rz_archive.rz_art IS NULL
HAVING ROUND(ssc_price, 2) != ROUND(goods_price, 2)
LIMIT 500000

2 个答案:

答案 0 :(得分:0)

这可行吗?

SELECT Count(*)
FROM rz_price
LEFT JOIN currencies ON currencies.`name` = 'USD'
LEFT JOIN  goods ON goods.id = rz_price.`rz_art`
LEFT JOIN rz_archive ON rz_archive.rz_art  = rz_price.rz_art
WHERE
 rz_archive.rz_art IS NULL
 AND (ROUND(IF(rz_price_grn != 0, rz_price_grn, ROUND(rz_price2 * currencies.`rate`)), 2) != ROUND(IF(price IS NULL, 0, price), 2))
--LIMIT 500000

答案 1 :(得分:0)

那么,

SELECT COUNT(
    SELECT IF(rz_price_grn != 0, rz_price_grn, ROUND(rz_price2 * currencies.`rate`)) AS `ssc_price`, rz_price_grn, rz_price2, IF(price IS NULL, 0, price) AS `goods_price`
    FROM rz_price
    LEFT JOIN currencies ON currencies.`name` = 'USD'
    LEFT JOIN  goods ON goods.id = rz_price.`rz_art`
    LEFT JOIN rz_archive ON rz_archive.rz_art  = rz_price.rz_art
    WHERE
     rz_archive.rz_art IS NULL
    HAVING ROUND(ssc_price, 2) != ROUND(goods_price, 2)
)

有效吗?