GROUP BY
而且CASE
应该够了
select t1.Account_Number, case when count(*) > 1 then 'Y' else 'N' end Is_multiple from table1 t1 inner join table2 t2 on t1.meter_id = t2.meter_id group by t1.Account_Number;
根据修改后的架构,这应该工作:
select t1.Account_Number, case when count(*) > 1 then 'Y' else 'N' end Is_multiple from table1 t1 inner join table2 t2 on t1.agr_id = t2.agr_id inner join table3 t3 on t2.meter_id = t3.meter_id group by t1.Account_Number;