Well, I can at least give you an idea :-)
I haven't been able to test the code but the idea should work. First, you find a list of all the different (param_name, param_value) pairs for each report, which includes the duplicates:
select s.report_id,P.param_name,PV.param_value
from Scheduled S
join Parameters P
on S.report_id = P.report_id
join Parametervalues PV on
S.id = PV.sched_id
P.id = PV.param_id
group by s.report_id, p.param_name, pv.param_value
Then you just enclose the above statement within another select that groups by just report_id+param_name and count how many lines for each pair:
select report_id, param_name
from
(select s.report_id,P.param_name,PV.param_value
from Scheduled S
join Parameters P
on S.report_id = P.report_id
join Parametervalues PV on
S.id = PV.sched_id
P.id = PV.param_id
group by s.report_id, p.param_name, pv.param_value) C
group by c.report_id, c.param_name
having count(*) > 1
Regards,
Palli
|