我在mysql中遇到了一个奇怪的问题。我编写了一个查询,将跨国数据聚合成每小时一次的数据块。在workbench查询窗口中,该查询非常有效。然后我将查询实现为一个存储过程,得到一个“错误代码:1054”。“字段列表”消息中的未知列“d.siteid”。
SELECT `d`.`SiteId`, `d`.`TransactionDate`, (`d`.`TimeGrouping` * 10000) as 'HourEndTime', Sum(`d`.`SalesAmount`) as 'TotalSales', count(`d`.`PosTransactionId`) as 'TransactionCount', Sum(`d`.`ItemCount`) as 'ItemCount', `d`.`Currency`
FROM (SELECT DISTINCT `SiteId`, `TransactionDate`, `TimeGrouping`, `SalesAmount`, `PosTransactionId`, `ItemCount`, `Currency`
FROM PosSalesDev.Transaction
WHERE `SiteId` = 31
AND `TransactionDate` = '2018-06-08') AS `d`
GROUP BY TransactionDate, TimeGrouping
ORDER BY HourEndTime;
存储过程中的查询:
CREATE DEFINER=`user`@`%` PROCEDURE `TransactionGet`(siteId varchar(10),
transactionDate Date)
BEGIN
# Query will remove duplicate records from the aggregated data
SELECT `d`.`SiteId`, `d`.`TransactionDate`, (`d`.`TimeGrouping` * 10000) as 'HourEndTime', Sum(`d`.`SalesAmount`) as 'TotalSales', count(`d`.`PosTransactionId`) as 'TransactionCount', Sum(`d`.`ItemCount`) as 'ItemCount', `d`.`Currency`
FROM (SELECT DISTINCT `SiteId`, `TransactionDate`, `TimeGrouping`, `SalesAmount`, `PosTransactionId`, `ItemCount`, `Currency`
FROM PosSalesDev.Transaction
WHERE `SiteId` = siteId
AND `TransactionDate` = transactionDate) AS `d`
GROUP BY TransactionDate, TimeGrouping;
END
任何帮助都将不胜感激。
谢谢你,乔迪。
1条答案
按热度按时间d4so4syb1#
避免将参数命名为列名。见13.6.4.2局部变量范围和分辨率。
尝试: