SQL 过程错误
更改为过程,在“PROCEDURE”处出现语法错误有什么想法吗?
CREATE PROCEDURE performance_Report
@startDate DATE,
@endDate DATE
AS
SELECT Salesrep.Name, SUM(OrderLine.Quantity) AS Total_Sold, SUM(OrderLine.UnitSellingPrice * Orderline.Quantity) AS Total_Value
FROM SalesRep, OrderLine, ShopOrder
WHERE ShopOrder.SalesRepID = SalesRep.SalesRepID
AND OrderLine.ShopOrderID = ShopOrder.ShopOrderID
AND ShopOrder.OrderDate BETWEEN @startDate AND endDate
GROUP BY SalesRep.SalesRepID, SalesRep.Name
ORDER BY Total_Value DESC;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
PostgreSQL 没有“CREATE PROCEDURE”。 报告您可能会遇到的大部分情况在其他数据库中需要存储过程可以在 PostgreSQL 中使用 CREATE FUNCTION。
PostgreSQL doesn't have "CREATE PROCEDURE". It is reported that most of what you might need stored procedures for in other databases can be done in PostgreSQL with CREATE FUNCTION.
不,你不能那样做。您希望视图按照 SalesRep.Name 进行聚合。您想要做的是过滤这些 SUM。您有两个选择:
编辑
因此,您更改了问题,现在您想要在 PostgreSql 中创建一个存储过程。您可能想看看这个: 。花点时间阅读它,在这个过程中获得的知识一定会有所帮助。而且,在您完成它的过程中,您可能会重新评估并认为对于像这样的简单查询来说您实际上并不需要这种功能。祝你好运。
No, you cannot do that. You want your view to result in an aggregation by SalesRep.Name. What you want to do is filtering those SUMs. You have two options:
EDIT
So, you changed the question and now you want to create a stored procedure in PostgreSql. You might want to take a look at this: A Basic Introduction to Postgres Stored Procedures. Take your time to read it, the knowledge acquired in the process will surely be helpful. And, on your way through it, you might reevaluate and think you don't really need that kind of functionality for a straightforward query such as this one. Good luck.
从视图定义之外,您无权访问基础表。
From outside of the view definition you don't have access to the underlying tables.
您确定您不是要使用
CREATE FUNCTION
:
Are you sure you didn't mean to use
CREATE FUNCTION
:您的
AND ShopOrder.OrderDate BETWEEN @startDate AND endDate
不应该是AND ShopOrder.OrderDate BETWEEN @startDate AND @endDate
吗?否则,如果您完全删除该行而不是存储过程,则此查询是否有效?
You have
AND ShopOrder.OrderDate BETWEEN @startDate AND endDate
shouldn't that beAND ShopOrder.OrderDate BETWEEN @startDate AND @endDate
?Otherwise does this query work if you remove that line entirely without being a stored procedure?
CREATE PROCEDURE
是在 PostgreSQL 版本 11 中引入的,因此,如果您使用的是早期版本,您将收到ERROR:在“PROCEDURE”处或附近出现语法错误
CREATE PROCEDURE
was introduced to PostgreSQL in version 11, so if you are using an earlier version you will getERROR: syntax error at or near "PROCEDURE"