1
SELECT
billing_line.id,
billing_line.active,
billing_line.account_id,
billing_line.billing_measure_id,
billing_line.site_id,
billing_line.rate,
billing_line.range_start,
billing_line.range_end,
billing_measure.`name` AS measure_name,
billing_service.`name` AS service_name,
billing_field_value.id as billing_field_value_id,
billing_field_value.billing_field_id,
billing_field_value.`value`
FROM
    billing_line,
    billing_service,
    billing_measure
INNER JOIN billing_field_value ON (  ( billing_field_value.BILLING_FIELD_ID = 3 AND billing_field_value.VALUE = 'Option 2')
                                   OR( billing_field_value.BILLING_FIELD_ID = 4 AND billing_field_value.VALUE = 'Option 5'))
WHERE
    billing_line.ACTIVE = 1
AND billing_line.ACCOUNT_ID = 1337
AND billing_line.SITE_ID IS NULL
AND billing_service.ID = 7
AND billing_measure.ID = 15
AND billing_line.BILLING_MEASURE_ID = billing_measure.ID
AND billing_measure.BILLING_SERVICE_ID = billing_service.ID
AND billing_field_value.BILLING_LINE_ID = billing_line.ID
ORDER BY
    billing_service.SORT ASC,
    billing_measure.SORT ASC,
    billing_line.RANGE_START ASC,
    billing_line.RATE ASC

这很自然地返回 billing_field_value.value 为“选项 2”或“选项 5”的值。这是一个过滤系统,它应该选择所有“选项 2”(对于字段 id 3),但也应该只选择“选项 5”(对于字段 id 4)

问题是返回的结果既有 'Option 2'->'Other Options' 也有 'Option 2'->'Option 5' - 因此有效地忽略第一个之后的任何“过滤器”。

我意识到“或”是这里问题的一部分,但是因为这些字段和值存储在相同的列中但可以有不同的值,所以使用“与”意味着它永远不会评估为真。

对于简单的东西,这可能是一个漫长而复杂的解释,但我很难过。有什么想法吗?

4

0 回答 0