我遇到了MySQL中的select语句问题。
我有两个声明略有不同,第一个似乎有效但第二个没有。第二个语句返回0结果。我错过了什么/做错了什么?
SET @maxOK = 1.2;
SET @minOK = .8;
SELECT *, fee - (receipts * -1) AS difference
FROM div.Data1
WHERE (receipts * -1) NOT BETWEEN (fee * @minOK) AND (fee * @maxOkay);
SELECT *, fee - (receipts * -1) AS difference,
receipts * -1 as rec,
fee * @minOk as min, fee * @maxOk as max
FROM div.Data1
WHERE (receipts * -1) BETWEEN (fee * @minOK) AND (fee * @maxOkay);
SELECT *, fee - (receipts * -1) AS difference,
receipts * -1 as rec,
fee * @minOk as min, fee * @maxOk as max
FROM div.Data1
答案 0 :(得分:0)
尝试在SELECT中包含where子句组件。 即:
SELECT (fee * @minOK) as wheremin, (fee * @maxOkay) as wheremax, *, fee - (receipts * -1) AS difference, receipts * -1 as rec, fee * @minOk as min, fee * @maxOk as max FROM div.Data1 WHERE (receipts * -1) BETWEEN (fee * @minOK) AND (fee * @maxOkay);
答案 1 :(得分:0)
您的陈述中有错误。您已声明@maxOk
,但在@maxOkay
子句中使用了BETWEEN
。
由于@maxOkay
未在任何地方声明,因此它已初始化为NULL
,因此您的陈述基本归结为
SET @maxOK = 1.2;
SET @minOK = .8;
SELECT *
, fee - (receipts * -1) AS difference
, receipts * -1 as rec
, fee * @minOk as min
, fee * @maxOk as max
FROM Data1
WHERE (receipts * -1) BETWEEN (fee * @minOK) AND NULL
语句应
SET @maxOK = 1.2;
SET @minOK = .8;
SELECT *
, fee - (receipts * -1) AS difference
, receipts * -1 as rec
, fee * @minOk as min
, fee * @maxOk as max
FROM Data1
WHERE (receipts * -1) BETWEEN (fee * @minOK) AND (fee * @maxOK);