Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Accounts Table
------------------
cases| type |
------------------
 A1  | UNDER
------------------
 A1  | UNDER
------------------
 B1  | OVER
------------------
 B1  | UNDER
------------------
 B1  | OVER
------------------
 C1  | OVER
------------------
 C1  | OVER
-----------------
 D1 | UNDER
----------------
 E1 | OVER
----------------
 E1 | UNDER


What I have tried:

1.COUNT THE CASES WHERE ALL ITERATION of TYPE IS "UNDER" FOR THE CASES
 (see A1 iteration is having all UNDER it would give COUNT 1)

i tried to get the record but its giving me every record which has "UNDER"
result count should be 1 only
select COUNT(CASEID) from ACCOUNTS WHERE TYPE="UNDER" -> its not giving proper result
Posted
Updated 25-Jul-19 12:02pm

Filtering "under" is a wrong approach because it remove information about not "under".
I would attack the problem with 2 cascading selects.
The first do a synthesis of database:
field CASEID
field records: count(CASEID)
field unders: sum(if(TYPE="UNDER", 1, 0))
SQL
select CASEID, count(CASEID) as records, sum(if(TYPE="UNDER", 1, 0)) as unders GROUP BY CASEID

caseid records unders
 A1     2       2
 B1     3       1
 C1     2       0
 D1     1       1
 E1     2       1

In the second, you compare records and unders to know which caseid to keep according to your needs.
Left as exercise.
 
Share this answer
 
v2
Read the question again: you've missed a bit.
It wants you to count every different cases value that has a type of 'UNDER', not a single value result:
A1 2
B1 1
C1 0
D1 1
E1 1
To do that, you will need a GROUP BY clause.

But it's your homework, so I'm not going to give you the code just like that!
Give it a try and see how far you can get...
 
Share this answer
 
Comments
Member 13047430 25-Jul-19 15:42pm    
its not a homework by the way its a scenerio i extracted from my project report.
and one more thing your understanding is wrong

i want the count of cases which is having UNDER only mean A1 is the only case where all are under so result of count will be 1


it will not count other cases because its not having all UNDER for a case

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900