在此 SQL SELECT 查询中的何处放置数字
Where to place numeric in this SQL SELECT query
我想知道 NUMERIC(5,2) 相对于我的 avg 的正确位置在下面的 SQL 查询中:
select distinct
b.name, avg(c.price) over (partition by b.name) as average_price
from
Catalog a
join
books b on (a.book_id = b.id)
join
movies c on (a.movie_id = c.id)
where
c.price is not null
and a.record >= 2
group by
b.name, c.price, average_price
到处都试过的感觉!
提前致谢。
我只取平均值:
select distinct b.name,
cast(avg(c.price) over (partition by b.name) as numeric(5,2)) as average_price
from ...
这假设您希望使用 price
列中的任何原始精度继续进行平均计算,并且您只想查看输出 numeric(5,2)
.
我想知道 NUMERIC(5,2) 相对于我的 avg 的正确位置在下面的 SQL 查询中:
select distinct
b.name, avg(c.price) over (partition by b.name) as average_price
from
Catalog a
join
books b on (a.book_id = b.id)
join
movies c on (a.movie_id = c.id)
where
c.price is not null
and a.record >= 2
group by
b.name, c.price, average_price
到处都试过的感觉!
提前致谢。
我只取平均值:
select distinct b.name,
cast(avg(c.price) over (partition by b.name) as numeric(5,2)) as average_price
from ...
这假设您希望使用 price
列中的任何原始精度继续进行平均计算,并且您只想查看输出 numeric(5,2)
.