我DELCARE @qty INT
时出现语法错误,因为SET qty = ...
和AND q = @qty
我不知道如何纠正这些语法错误!
这里的程序:
CREATE PROCEDURE test(target INT)
BEGIN
DECLARE qty INT
-- Get closest qty
@qty = SELECT q
FROM MH
ORDER BY ABS(@target - q) ASC
LIMIT 1
-- use that "actual" qty in your query
SELECT ((p+m)*((valore+100)/100))
FROM PL
JOIN TV
JOIN MH
WHERE Date = '20130717'
AND End = ''
AND q = @qty
END
答案 0 :(得分:0)
CREATE PROCEDURE test(target INT)
BEGIN
DECLARE qty INT default 0;
SELECT q into qty
FROM MH
ORDER BY ABS(target - q) ASC
Limit 1;
SELECT ((p+m)*((valore+100)/100))
FROM PL
JOIN TV
JOIN MH
WHERE Date = '2013/07/17'
AND End = ''
AND q = qty;
END