Sql 语法接近,但我无法识别问题
我不断发现以下错误: 味精156,第15级,状态1,第4行Sql 语法接近,但我无法识别问题,sql,sql-server,syntax,Sql,Sql Server,Syntax,我不断发现以下错误: 味精156,第15级,状态1,第4行 关键字“as”附近的语法不正确 味精156,第15级,状态1,第10行 关键字“between”附近的语法不正确 我看不出问题所在 use leads; select * (select max(HighTrw) from (values (trw1), (trw2), (trw21)) as Value (HighTrw)) as [high_trw] from dbo.spi s Where
关键字“as”附近的语法不正确 味精156,第15级,状态1,第10行
关键字“between”附近的语法不正确 我看不出问题所在
use leads;
select *
(select max(HighTrw)
from (values (trw1), (trw2), (trw21)) as Value (HighTrw)) as [high_trw]
from
dbo.spi s
Where
(select max(HighTrw)
from (values (trw1), (trw2), (trw21)) As updatedate (HighTrw)) between '600' and '625'
您的代码看起来有点像SQL Server代码,因此我将使用该语法 你大概打算这样做:
select s.*, ss.high_trw
from dbo.spi s outer apply
(select max(Value.HighTrw) as high_trw
from (values (s.trw1), (s.trw2), (s.trw21)
) as Value(HighTrw)
) ss
where ss.high_trw between 600 and 625;
注:
- 您可以使用
将子查询放入apply
子句中from
- 一个明显的问题是在相关子查询之前缺少逗号
- 您应该学会限定所有列名。这对于相关子查询尤其重要
和600
看起来像数字,而不是字符串。如果是这样,常数不应该有引号625
use leads;
-- There's no comma "," after the "*"
select*
-- This look like it belongs in the "from" section as a subquery, eg "(select ...) as sub"
-- You can then reference all of its contents in the main select using "sub.*"
(select max(HighTrw) from (values (trw1), (trw2), (trw21)) as Value(HighTrw)) as [high_trw]
from dbo.spi s
Where (select max(HighTrw)
-- Haven't seen this way of specifying a table before, is it valid?
-- Why not explicitly define a temporary table above with the data you want, _before_ starting the query? - makes the code cleaner/clearer, IMO
from (values (trw1), (trw2), (trw21)) As updatedate (HighTrw)) between '600' and '625'
-- There's no final ";" to terminate the query, might not be absolutely necessary, but good habit,
-- because at some point, this code's going to dovetail into some other code, and the compiler will probably throw a wobbly
该查询是特定于产品的。您使用的是哪种dbms?要启动,请选择空格星号逗号
select*,
Yes对不起,SQL server就是dbms。失踪的人,耍了把戏谢谢大家的帮助。