使用存储过程的语法错误

发布于 2025-02-14 01:12:54 字数 1488 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终陌 2025-02-21 01:12:55

不知道为什么首先需要这里的临时表。您可以通过一些有条件的聚合可以大大简化这一点。这将通过职位返回性别计数。

CREATE OR ALTER PROCEDURE dbo.EmployeeGenderbyJobTitle
AS
BEGIN
    SET NOCOUNT ON;

    select Sum(case when e.Gender = 'M' then 1 end) as MaleEmployees
        , Sum(case when e.Gender = 'F' then 1 end) as FemaleEmployees
        , e.JobTitle
    from humanresources.employee AS e
    group by e.JobTitle
END

Not sure why you need the temp tables here in the first place. You could simplify this considerably with some conditional aggregation. This will return the count of gender by job title.

CREATE OR ALTER PROCEDURE dbo.EmployeeGenderbyJobTitle
AS
BEGIN
    SET NOCOUNT ON;

    select Sum(case when e.Gender = 'M' then 1 end) as MaleEmployees
        , Sum(case when e.Gender = 'F' then 1 end) as FemaleEmployees
        , e.JobTitle
    from humanresources.employee AS e
    group by e.JobTitle
END
一城柳絮吹成雪 2025-02-21 01:12:55

go信号在sql Server中批量的末端,因此您不能在批处理中间使用GO功能等)

参考

GO signals the end of a batch in SQL Server so you can't use go in middle of a batch (a procedure, function etc.)

Reference SQL Server docs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文