2

我似乎无法获得以下查询的结果,以下查询返回 NULL

查询联合

"SELECT isbn    

    FROM ".TBL_BOOKS." 

    WHERE rank < 200000 AND rank IS NOT NULL 
    AND lowest_new_price < amazon_new_price/100*80 
    AND amazon_new_price < 9999 
    AND ROUND((amazon_new_price/100*80) - lowest_new_price) > (lowest_new_price/100*".MARGIN.") 

UNION 

SELECT isbn 

    FROM ".TBL_BOOKS." 

    WHERE rank < 200000 AND rank IS NOT NULL 
    AND lowest_used_price < amazon_used_price/100*80 
    AND amazon_used_price < 9999 
    AND amazon_used_price < amazon_new_price 
    AND ROUND((amazon_used_price/100*80) - lowest_used_price) > (lowest_used_price/100*".MARGIN.") 

ORDER BY rank ASC";

但是这两个quires自己工作得很好

查询 1

"SELECT isbn    

    FROM ".TBL_BOOKS." 

    WHERE rank < 200000 AND rank IS NOT NULL 
    AND lowest_new_price < amazon_new_price/100*80 
    AND amazon_new_price < 9999 
    AND ROUND((amazon_new_price/100*80) - lowest_new_price) > (lowest_new_price/100*".MARGIN.") 
ORDER BY rank ASC";

查询 2

"   SELECT isbn 

        FROM ".TBL_BOOKS." 

        WHERE rank < 200000 AND rank IS NOT NULL 
        AND lowest_used_price < amazon_used_price/100*80 
        AND amazon_used_price < 9999 
        AND amazon_used_price < amazon_new_price 
        AND ROUND((amazon_used_price/100*80) - lowest_used_price) > (lowest_used_price/100*".MARGIN.") 

ORDER BY rank ASC";

如果我打破联合并分别运行两个查询,我不会有任何问题,但由于某种原因,联合查询不起作用,可能是什么问题?谢谢

4

1 回答 1

3

我认为——当你在联合中使用“order by”子句时——那么“order by”参数必须是单个查询返回的字段之一。

于 2012-08-14T18:00:32.527 回答