0

私の質問:

SELECT *
FROM ranks
WHERE
    (price = 25.00 AND accumulate = 0)
    OR
    (price <= (SELECT SUM(amount) FROM donations WHERE username = 'username' AND amount IN (SELECT price FROM ranks WHERE accumulate = 1)))
ORDER BY price
DESC LIMIT 1

基本的に、一致するものが見つかった場合は最初のwhere句を返し、それ以外の場合は2番目の句を返します。

4

2 に答える 2

1

このクエリは機能します

SELECT *
FROM ranks
WHERE price = 25.00 AND accumulate = 0

UNION ALL

SELECT *
FROM ranks
WHERE NOT EXISTS(SELECT *
                  FROM ranks
                  WHERE price = 25.00 AND accumulate = 0)
      AND (price <= (SELECT SUM(amount) FROM donations WHERE username = 'username' AND        amount IN (SELECT price FROM ranks WHERE accumulate = 1)))
ORDER BY price
DESC LIMIT 1
于 2013-01-28T06:10:10.890 に答える
0

このクエリを IF で試してください

SELECT *
FROM ranks
WHERE if(price = 25.00,accumulate = 0, price <= (SELECT
                           SUM(amount)
                         FROM donations
                         WHERE username = 'username'
                             AND amount IN(SELECT
                                     price
                                   FROM ranks
                                   WHERE accumulate = 1)))
ORDER BY price DESC
LIMIT 1
于 2013-01-28T06:08:14.127 に答える