首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SubQueries -仅使用一条Where语句

问SubQueries -仅使用一条Where语句
EN

Stack Overflow用户
提问于 2010-10-29 19:50:36
回答 1查看 37关注 0票数 0

我有下面的查询,每次我改变它,我需要改变股票客户端i。我希望我只有一个where语句应用于所有子查询。

有没有一种方法可以应用相同的代码来返回多行?我希望显示所有股票客户I的结果,而不是只显示1个。

代码语言:javascript
复制
Select 

(Select distinct SName FROM classifiedadmin.readOnly_CoreData) as SupplierName,

(SELECT COUNT(*) FROM classifiedadmin.readOnly_CoreData where Successful= 1 and StockClientID=3) as TotalLive,

(Select count(*) FROM classifiedadmin.readOnly_CoreData where length(DetailDesc) > 200 and StockClientID= 3) as DescriptionOver200,

(select count(*) from classifiedadmin.readOnly_CoreData where busruleViolated=1 and StockClientID = 3) as BusinessRuleViolated,

(Select count(*) FROM classifiedadmin.readOnly_CoreData where StockClientID = 3
and Successful=0
and busruleviolated=0
and Edition not like '%auto%'
and Edition not like '%shift%'
and Edition not like '%tronic%'
and Edition not like '%van%'
and Edition not like '%DSG%') as UnadvertisedManual;
EN

回答 1

Stack Overflow用户

发布于 2010-10-29 19:54:20

代码语言:javascript
复制
SELECT  MIN(sname),
        SUM(Successful= 1),
        SUM(length(DetailDesc) > 200),
        SUM(busruleViolated=1),
        SUM(
        Successful=0
        and busruleviolated=0
        and Edition not like '%auto%'
        and Edition not like '%shift%'
        and Edition not like '%tronic%'
        and Edition not like '%van%'
        and Edition not like '%DSG%'
        )
FROM    classifiedadmin.readOnly_CoreData
WHERE   StockClientID = 3

请注意,如果给定的SELECT DISINCT sname中有多个sname,则当前使用stockclientid的查询将失败。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4051525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档