现在系统中三个表Property,Sheetitem,BusinessModel
Property(mb_id,prop_id,prop_name...) 用于存放指标属性
Sheetitem(bm_id,bs_id,mb_id,prop_id...)用于存放表单中的项目
BusinessModel(bm_id,bs_id,bs_name...) 用于存放系统中的表单查询指标重名一次的sql是:
select * from Property
where prop_name in
(select prop_name from (select prop_name,count(*) count from Property group by prop_name) where count =1 )因为一条Property中的记录可能会在Sheetitem被引用多次,并且在Sheetitem中有不同的bm_id和bs_id,那么当一个指标被两个以上不同的表单引用时我该怎么写sql查询出来该指标被哪几个表单引用了?
Property(mb_id,prop_id,prop_name...) 用于存放指标属性
Sheetitem(bm_id,bs_id,mb_id,prop_id...)用于存放表单中的项目
BusinessModel(bm_id,bs_id,bs_name...) 用于存放系统中的表单查询指标重名一次的sql是:
select * from Property
where prop_name in
(select prop_name from (select prop_name,count(*) count from Property group by prop_name) where count =1 )因为一条Property中的记录可能会在Sheetitem被引用多次,并且在Sheetitem中有不同的bm_id和bs_id,那么当一个指标被两个以上不同的表单引用时我该怎么写sql查询出来该指标被哪几个表单引用了?
where a.bm_id=b.bm_id and a.bs_id=b.bs_id
and b.mb_id=c.mb_id and b.prop_id=c.prop_id
and c.mb_id=4 and c.prop_id=265
如上述sql可以查询出某个指标被哪些表单引用了,我可以将其合并成一条与mb_id + prop_id对应的结果吗?还有,Propperty里有几千条重名的指标,我怎么将这些引用的表单名称与指标查询到一个结果集中?
(select bm_id,mb_id,count(1) ct from Sheetitem
group by bm_id,mb_id having ct>1 )mm
where y.mb_id=m.mb_id
and m.mb_id=mm.mb_id
and y.pro_id=? // 你的条件
select mb_id, prop_id, bm_id, bs_id
from Sheetitem
where mb_id = ? and prop_id = ?
group by mb_id, prop_id
having count(*) > 1需要表单名称的话就再结合一下表单表就成了