|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
query help needed
I am trying to create a query which will return a count of Ys and Ns from one of the columns.
The following statement will return a count of the Ys but I want a third column to show the Ns. SELECT DISTINCT a.name, COUNT(b.response) FROM a,b where a.id=b.id AND b.response='Y' GROUP BY a.name; How can I modify this query to include a third column with a count of b.response where b.response='N' Any help would be greatly appreciated. |
|
#2
|
||||
|
||||
|
Code:
select a.name
, sum(case when b.response='y'
then 1 else 0 end
) as Yresponses
, sum(case when b.response='n'
then 1 else 0 end
) as Nresponses
from a
inner
join b
on a.id = b.id
group
by a.name
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > query help needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|