开发者

SubQueries - using only one Where statement

开发者 https://www.devze.com 2023-01-22 18:40 出处:网络
I have the below query, everytime i change it i need to change the stockclientid. I would like it where i only have one where statement to apply to all the sub queries.

I have the below query, everytime i change it i need to change the stockclientid. I would like it where i only have one where statement to apply to all the sub queries.

Is there also a way to apply the same code to return multiple rows? I would like to have the results display for all stockclientIDs rather than just 1.

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 no开发者_JAVA技巧t like '%shift%'
and Edition not like '%tronic%'
and Edition not like '%van%'
and Edition not like '%DSG%') as UnadvertisedManual;


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

Note that your current query with SELECT DISINCT sname will fail if there is more than one sname within given stockclientid.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号