Click to See Complete Forum and Search --> : Select - Need result count from two filters


mikeysql
04-21-2009, 06:57 PM
What I am trying to do is get results from two different filters yet have access to both sets of data in one sql statement.

EX.

Select Count(driverType) from driver where driverType <> 'large'

(returns say 10 records)

And

Select count(driverType) from driver where driverType = 'large'

(returns 2 records)


I'd like to be able combine them to gain access to both sets of records returned.

I want to display them in one column like:

column1
10 / 2

Is it possible? My query is much more complicated with subquerys and joins but this is the idea.

thanks

xvszero
04-22-2009, 03:29 PM
I'm not sure exactly what you are trying to do but something I recently put together might be close...


SELECT DISTINCT aaadlr.name, b.current, c.delinquent, a.total FROM aaadlr

LEFT OUTER JOIN (SELECT aaadlr.mdlrno as mdlra, count(*) as total FROM aaaacct
INNER JOIN aaadlr on aaaacct.dlrno = aaadlr.dlrno
WHERE aaaacct.pstatus='A'
GROUP BY aaadlr.mdlrno) a ON (aaadlr.dlrno = a.mdlra)

LEFT OUTER JOIN (SELECT aaadlr.mdlrno as mdlrb, count(*) as current FROM aaaacct
INNER JOIN aaadlr on aaaacct.dlrno = aaadlr.dlrno
WHERE aaaacct.pstatus='A' AND aaaacct.daysdelin <= '30'
GROUP BY aaadlr.mdlrno) b ON (aaadlr.dlrno = b.mdlrb)

LEFT OUTER JOIN (SELECT aaadlr.mdlrno as mdlrc, count(*) as delinquent FROM aaaacct
INNER JOIN aaadlr on aaaacct.dlrno = aaadlr.dlrno
WHERE aaaacct.pstatus='A' AND aaaacct.daysdelin >= '31'
GROUP BY aaadlr.mdlrno) c ON (aaadlr.dlrno = c.mdlrc)

WHERE (a.total IS NOT NULL)

ORDER BY aaadlr.name


You can see that b.current, c.delinquent, and a.total are all columns created by their own SELECT statements...