Question : Generate report/query from sample data

Database: Oracle 9i
Crystal Reports: 10
Sample Database Table data  is as follows.
TableName: VehInfo
(Val1 and Val2 have no significance in this report)
VehID  Val1     Val2
100      10        15  
100      11        12  
101      12        11  
102      10        16  
102      13        17  
102      15        18  
103      18        19  
103      11        11  
104      10        12
105      20        15  
105      25        18  
106      17        15
106      18        30  
106      19        31  
106      11        44  
107      10        13

Now I want to generate following report from this data.  Where count is based upon the VehID field. i.e

No of Vehicles with 1 Record = 3 (This means that there are 3 vehicles with just one record in the table i.e 101,104,107)
No of Vehicles with 2 Records = 3 (i.e 100,103,105)
No of Vehicles with 3 Records = 1
No of Vehicles with 4 or more Records = 1

How to produce this type of report using Crystal Reports 10? or even with a Query?

Answer : Generate report/query from sample data

All you need is :

select *
from
(
select vehid, count(1) mycount
from VehInfo
group by vehid
)
where mycount = 1 ;  
--> if you have 1, it will get you all veh which had only 1 record i.e 101,104,107

so just change 1 to 2 and 3 it will give all the data you wanted for the other queries.

for the last query, you can change it to

select *
from
(
select vehid, count(1) mycount
from VehInfo
group by vehid
)
where mycount >= 4 ;  

Thanks
Random Solutions  
 
programming4us programming4us