此 Data Explorer SQL 查询有什么问题?
我正在尝试在 Stack* Data Explorer我输入了多少?查询一个>。
修改现有查询让我到目前为止:
-- How much did I type?
DECLARE @UserId int = ##UserId##
select sum(len(Body)) AS 'Posts' from posts where owneruserid = @UserId,
select sum(len(Text)) AS 'Comments' from comments where userid = @UserId,
(select sum(len(Body)) from posts where owneruserid = @UserId +
select sum(len(Text)) from comments where userid = @UserId) AS 'Total'
我期望三列和一行,如下所示:
Posts Comments Total
1234 5678 6912
但是存在一些语法问题,因此我得到:
错误:“,”附近的语法不正确。 “,”附近的语法不正确。不正确 关键字“select”附近的语法。 “)”附近的语法不正确。
正确的语法是什么?
I am trying to write a How much did I type? query on Stack* Data Explorer.
Modifying an existing query got me this far:
-- How much did I type?
DECLARE @UserId int = ##UserId##
select sum(len(Body)) AS 'Posts' from posts where owneruserid = @UserId,
select sum(len(Text)) AS 'Comments' from comments where userid = @UserId,
(select sum(len(Body)) from posts where owneruserid = @UserId +
select sum(len(Text)) from comments where userid = @UserId) AS 'Total'
I am expecting three columns and one row, something like this:
Posts Comments Total
1234 5678 6912
But there is some syntax problem, due to which I get:
Error: Incorrect syntax near ','.
Incorrect syntax near ','. Incorrect
syntax near the keyword 'select'.
Incorrect syntax near ')'.
What is the correct syntax for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个有效的查询:
Here is a working query:
我会这样做...
I would do it this way...
您好,您的问题是您有 3 个语句连接到 1 个语句 - 只需从 if 中生成一个语句:
就像
希望我输入正确一样...
Hi your problem is that you have 3 Statements concatenated to 1 Statement - just make one Statement out of if:
like
Hope I typed correct ...