|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
SQL Query 2
I have a table as such
Name A B asdf h k asdf h asdf j k asdf k h jklm h k jklm j k jklm h j what I want to do is this get the total occurances of 'h' in field A and B and group by name so my output would look like this Name h k asdf 3 3 jklm 2 2 hopefully this makes sense.. |
|
#2
|
||||
|
||||
|
this is just like your other question
Code:
select Name
, sum(
case when A='h' or B='h' then 1 else 0 end
) as h
, sum(
case when A='k' or B='k' then 1 else 0 end
) as k
from yourtable
group
by Name
rudy http://r937.com/ |
|
#3
|
||||
|
||||
|
thanks for ur response rudy
![]() however it doesn't seem to work. This is what I have Code:
SELECT [Incident Reports].Program, SUM( CASE WHEN ([Incident Reports].[Code (a)] = 'AV') OR ( [Incident Reports].[Code (b)]='AV') THEN 1 ELSE 0 END) AS AV FROM [Incident Reports] WHERE ((([Incident Reports].[Date of Incident]) Between #1/1/2002# And #4/30/2003#)) GROUP BY [Incident Reports].Program; it gives me the following error Syntax error (missing operator) in query operation.. ![]() |
|
#4
|
||||
|
||||
|
hmm.. I think the solution u provided only works on MS SQL Server
|
|
#5
|
||||
|
||||
|
the solution i gave is standard sql
you did not say what your database is, so if it doesn't support standard sql, that'd be your problem, no? i shall make a guess that you're using microsoft access try this -- Code:
select Program
, sum(
iif([Code (a)]='AV',1,
iif([Code (b)]='AV',1,0))
) as AV
from [Incident Reports]
where [Date of Incident]
between #1/1/2002# And #4/30/2003#
group
by Program
rudy Last edited by r937 : June 24th, 2003 at 05:24 PM. |
|
#6
|
||||
|
||||
|
hey.. thanks..
thats what I did.. and it worked.. ![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > SQL Query 2 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|