Sunday, February 19, 2012

a query for a view

Hello,
I have a View called View1 with the field ID, F1, F2, F3. Now I need to
check if (Total F1 < Total F2 + Total F3) per ID, if yes fetch all records
(so if condition matches, I need to bring rows, not only totals) how can I
write my view query to handle this?
Thanks,Try,
select v1.[id], v1.f1, v1.f2, v1.f3
from
v1
inner join
(
select [id]
from v1
group by [id]
having sum(f1) < sum(f2 + f3)
) as v2
on v1.[id] = v2.[id]
AMB
"JIM.H." wrote:

> Hello,
> I have a View called View1 with the field ID, F1, F2, F3. Now I need to
> check if (Total F1 < Total F2 + Total F3) per ID, if yes fetch all records
> (so if condition matches, I need to bring rows, not only totals) how can I
> write my view query to handle this?
> Thanks,
>|||this should do:
select *
from view1
where id in(select id
from view1
group by id
having sum(f1)<(sum(f2)+sum(f3))
)
-oj
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:8A8C406B-8576-43F1-A679-F4A3C0EED5D4@.microsoft.com...
> Hello,
> I have a View called View1 with the field ID, F1, F2, F3. Now I need to
> check if (Total F1 < Total F2 + Total F3) per ID, if yes fetch all records
> (so if condition matches, I need to bring rows, not only totals) how can I
> write my view query to handle this?
> Thanks,
>|||It seems it is working, however in case of equality I still see the records,
I should not see anything for that ID if sum(f1) = sum(f2 + f3)
What is problem here?
"Alejandro Mesa" wrote:
[vbcol=seagreen]
> Try,
> select v1.[id], v1.f1, v1.f2, v1.f3
> from
> v1
> inner join
> (
> select [id]
> from v1
> group by [id]
> having sum(f1) < sum(f2 + f3)
> ) as v2
> on v1.[id] = v2.[id]
>
> AMB
> "JIM.H." wrote:
>

No comments:

Post a Comment