sql - SQL 选择语句语法问题
问题描述
下面的代码出现错误,抱歉,这可能是一个非常简单的问题,但我真的不明白为什么它不起作用。
我收到“第 9 行,第 1 列'from' 附近的语法不正确”错误。
select distinct
b.Identifier,
(b.Low+ b.High) / 2 as bAverage,
m.Average as mAverage,
coalesce(
case when mAverage not null then ((((b.Low + b.High) / 2) + m.Average) / 2) else null end,
case when mAverage is null then ((b.Low + b.High) / 2)) end as TotalAvg,
(b.Volume + m.Qty) as TotalVolume
from table_b_data b
full outer join table_m_data m on b.Identifier=m.Identifier
解决方案
你coalesce()
没有关闭的paren。我可以这样写:
coalesce( m.average / 4 + (b.Low + b.High) / 4,
(b.Low + b.High) / 2
) as TotalAvg,
case
不是必需的,因为算术表达式将返回NULL
。我只是改写了算术(希望是正确的!)以减少括号的数量。
推荐阅读
- c# - 表未在 C# 上更新
- c++ - Qt (C++) 设置 QWidgetTab 中各个选项卡的颜色
- reactjs - Formik + React-semantic-ui
- javascript - 我想在 Datatables 中使用 Div 结构而不是 Table。是否可以?
- python - Chrome 在一段时间后关闭并产生错误 selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service in python
- reactjs - Options React Select 中的可选字段
- python - 用于查找 SQL 语句并将其转换为 Redshift 表达式的 Python 正则表达式
- javascript - 我应该如何计算 3D Mesh 文件的表面积
- java - 在 Android Studio 中加载数据库数据失败
- vba - EXCEL VBA,搜索行错误1004