select * ,(case when (select count(*) from 从表 where 从表.rowid=主表.rowid group by case when 从表.planamount=从表.stockamount then 1 else 2 end)>1 then '否' else '是' end ) from 主表
Select *, case when exists(select 1 from 从表 where 从表.rowid = 主表.rowid and planamount <> stockamount) then '否' else '是' end as 新增列 from 主表
select a.*, case when (select count(*) from 从表 where rowid = a.rowid and planamount <> stockamount) > 0 then '否' else '是' end as 新增列 from 主表 a
select a.*, (case when sum(mplanamount)=sum(stockamount) then '是' else '否' end from 从表 group by rowid where rowid=a.rowid ) as 标志 from 主表 a
select a.*,case when b.rowid is null or a.planamount<>b.stockamount then '否' else '是' end as 是否相等 from 主表 a left join 从表 b on a.rowid=b.rowid
呵呵,打了个懒主意,利用了字符中'否'<'是'的特性,^O^ select a.rowid, a.code, a.[name], min(case when planamount = stockamount then '是' else '否' end) as '标识' from 主表 as a INNER JOIN 从表 as b ON a.rowid = b.rowid group by rowid order by rowid
,(case
when (select count(*) from 从表 where 从表.rowid=主表.rowid group by case when 从表.planamount=从表.stockamount then 1 else 2 end)>1 then '否' else '是' end
) from 主表
from 主表
from 主表 a
from 从表 group by rowid where rowid=a.rowid ) as 标志
from 主表 a
from 主表 a left join 从表 b on a.rowid=b.rowid
select
a.rowid,
a.code,
a.[name],
min(case
when planamount = stockamount then '是'
else '否'
end) as '标识'
from
主表 as a
INNER JOIN
从表 as b
ON
a.rowid = b.rowid
group by rowid
order by rowid