I’ll try and describe best I can. Working with a bad data model.
Table1
id, name, area, bla1, bla2, bla3
Table2
table1_ID, stuff1, stuff2, ID
trigger on table1
insert row in table2 if table1 is updated
In table1 I have 10 different area, only 186 rows, not so much I can’t do this manually in like 2 seconds with Excel but I want to create realtime report.
The report would be
area1 - %complete
area2 - %complete
area3 - %complete
etc.....
When a row is updated in table1 the trigger inserts some stuff in table2 indicating ‘complete’.
I can do (probably really bad form)
select
(select count(*) from table1 a where a.id in (select id from table2))
/
(select count(*) from table1)
*100
This gives me an overall percentage complete.
I was thinking of adding where clauses to each of the selects, hard coding ‘area’ and then union TEN times. Ugh, tell me there is a better way to get this in one report.
Obviously this query is a fail
select area,
(
(select count(*) from table1 a where a.id in (select id from table2))
/
(select count(*) from table1)
*100) from table1
group by area
I figure group by has got to fit in there somewhere. Thanks in advance!
1 Answer