gpt4 book ai didi

sql - SQL Server中如何计算不同的列

转载 作者:行者123 更新时间:2023-12-02 22:03:31 25 4
gpt4 key购买 nike

请帮帮我..

我运行这个查询:

select 
distinct barang, COUNT(*) as jumlah, CAST(COUNT(*) as float) / 6
from
tbltes
group by
barang
Having
CAST(COUNT(*) as float) / 6 >0.2

现在..我想计算上面查询显示的所有行..

我试过这个查询..

 select 
count (distinct barang)
from
tbltes
group by
barang
having
CAST(COUNT(*) as float) /6 > 0.2

但并不像我预期的那样......

所以我需要你的帮助大师...

最佳答案

只需将现有查询用作子查询即可。顺便说一下,如果您有 group by 子句,则不需要 select distinct

select count(distinct sq.barang)
from
(
select barang as barang
,COUNT(*) as jumlah
from tbltes
group by
barang
) sq
where cast(sq.jumlah as float)/6 > 0.2

这是 SQL Fiddle

关于sql - SQL Server中如何计算不同的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16497761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com