我似乎无法获得以下查询的结果,以下查询返回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";
如果我分解了联盟并单独运行了两个查询我就没有问题,但由于某些原因UNION查询不起作用,可能是什么问题?感谢
答案 0 :(得分:3)
我认为 - 当您在联合中使用'order by'子句时 - 'order by'参数必须是各个查询返回的字段之一。