英文:
How to use distinct in sub select
问题
I have trouble to get distinct count of column
.
The result I get right now is total of all not different ones.
This select is as a sub select
select count (distinct tss.Deliverypostadre) from Shipment tss
where tss.DATAAREAID='wh' and tss.PARTITION=1234) as client_count
And if I just go using distinct
distinct s.Deliverypostadre as Client_count
Msg 156, Level 15, State 1, Line 105 Incorrect syntax near the keyword
'distinct'.
can't figure out how to make it work.
英文:
Hello I have trouble to get distinct count of column
.
The result I get right now is total of all not different ones.
This select is as a sub select
select count (distinct tss.Deliverypostadre) from Shipment tss
where tss.DATAAREAID='wh' and tss.PARTITION=1234) as client_count
And if I just go using distinct
distinct s.Deliverypostadre as Client_count
> Msg 156, Level 15, State 1, Line 105 Incorrect syntax near the keyword
> 'distinct'.
can't figure out how to make it work.
答案1
得分: 1
请检查以下查询:
选择 .. 在(选择计数(不同 tss.Deliverypostadre )作为 client_count 从 Shipment tss
其中 tss.DATAAREAID='wh' 和 tss.PARTITION=1234)
选择 Code 从 [dbo].[Codes] where codeId 在(选择计数(不同 Code)作为 code 从 [dbo].[Codes])
英文:
Please Check below query
Select ..in (select count(distinct tss.Deliverypostadre) as client_count from Shipment tss
where tss.DATAAREAID='wh' and tss.PARTITION=1234)
Select Code from [dbo].[Codes] where codeId in (select count (distinct Code) as code from [dbo].[Codes])
答案2
得分: 0
这部分可以翻译如下:
这应该有效:
选择 . . .
(选择 count(distinct tss.Deliverypostadre)
从发货 tss
其中 tss.DATAAREAID = 'wh' 且 tss.PARTITION = 1234
)作为客户数量
从 . . .
一些数据库可能对 count
和 (
之间的空格有问题,但语法基本上看起来是正确的。
英文:
This should work:
select . . .
(select count(distinct tss.Deliverypostadre)
from Shipment tss
where tss.DATAAREAID = 'wh' and tss.PARTITION = 1234
) as client_count
from . . .
Some databases might have a problem with the space between count
and (
. but the syntax basically looks correct.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论