我的存储过程的行为很奇怪。
我的测试SQL查询如下
SET @Latitude = '45.512573';
SET @Longitude = '-122.661276';
SET @OrderDateTime = '2018-11-13 09:23:45';
SET @NumberOFRecords = 6;
SET @RecordsOffSet = 0;
SELECT
listings.LISTING_MAX_QUANTITY,
@TOTAL_ORDERS := SUM(order_items.ORDER_QUANTITY) AS TOTAL_ORDERS,
@REMAINING_ORDER_ITEMS := (listings.LISTING_MAX_QUANTITY - @TOTAL_ORDERS) AS REMAINING_ORDER_ITEMS
FROM listings
INNER JOIN order_items ON order_items.ORDER_LISTING_ID = listings.LISTING_ID AND DATE(order_items.ORDER_REQUIRED_DATE_TIME) = DATE(@OrderDateTime)
WHERE listings.LISTING_ID IN (SELECT listing_region.LIST_REGION_LISTING_ID FROM listing_region WHERE listing_region.LIST_REGION_REGION_ID IN (SELECT REGION_ID FROM region WHERE CONTAINS(REGION_POLYGON, point(@Latitude, @Longitude))))
AND listings.LISTING_MAX_QUANTITY > 99
AND TIME(@OrderDateTime) BETWEEN LISTING_START_TIME AND LISTING_END_TIME;
当我用数量更新order_item表时,REMAINING_ORDER_ITEMS在第一次调用中不会得到更新。在第二次通话中是正确的。这是为什么?我的查询如何记住上一次通话?