给你个例子,参考下吧
select * from D
WHERE ID IN (SELECT ID FROM
(SELECT 字段 AS M from A
UNION ALL
SELECT 0-字段 AS M from B
UNION ALL
SELECT 0-字段 AS M from C )
GROUP BY ID
HAVING SUM(M)<0)
select * from D
WHERE ID IN (SELECT ID FROM
(SELECT 字段 AS M from A
UNION ALL
SELECT 0-字段 AS M from B
UNION ALL
SELECT 0-字段 AS M from C )
GROUP BY ID
HAVING SUM(M)<0)
WHERE ID IN (SELECT ID FROM
(SELECT ID,字段 AS M from A
UNION ALL
SELECT ID,0-字段 AS M from B
UNION ALL
SELECT ID,0-字段 AS M from C )
GROUP BY ID
HAVING SUM(M)<0)
select *
from D
where fk_c in (select id
from C
where value_c > (select abs((select sum(value_a) from a) -
(select sum(value_b) from B))
from dual));
create table A (
id number(4);
name varchar2(32)
);create table B(
id number(4),
b_area number(32);
);create table c (
a_id number(4),
B_id number(4)
);create table d (
a_id number(4),
d_area number(32)
);create table e(
valname varchar(32),
value number(18)
);传name到a表查出a_id用id去c中查b_id然后去b表中查出b_area并求和
同时a_id 闯入d表中查询d_id并求和
然后再将两个和求差,并要求差值小于e表中valname为test的value值
然后在将满足以上条件的a表中的信息返回
create table A (
id number(4);
name varchar2(32)
);create table B(
id number(4),
b_area number(32);
);create table c (
a_id number(4),
B_id number(4)
);create table d (
a_id number(4),
d_area number(32)
);create table e(
valname varchar(32),
value number(18)
);传name到a表查出a_id用id去c中查b_id然后去b表中查出b_area并求和
同时a_id 闯入d表中查询d_id并求和
然后再将两个和求差,并要求差值小于e表中valname为test的value值
然后在将满足以上条件的a表中的信息返回
create table A (
id number(4);
name varchar2(32)
);create table B(
id number(4),
b_area number(32);
);create table c (
a_id number(4),
B_id number(4)
);create table d (
a_id number(4),
d_area number(32)
);create table e(
valname varchar(32),
value number(18)
);传name到a表查出a_id用id去c中查b_id然后去b表中查出b_area并求和
同时a_id 闯入d表中查询d_id并求和
然后再将两个和求差,并要求差值小于e表中valname为test的value值
然后在将满足以上条件的a表中的信息返回select t1.a_id, t1.name, t1.s1 - t2.s2
from (select a.a_id, a.name, sum(b.b_area) s1
from a, b, c
where a.a_id = c.a_id
and c.b_id = b.id
and a.name = p_name
group by a.a_id, a.name) t1,
(select a.a_id, a.name, sum(d.d_area) s2
from a, d
where a.a_id = d.a_id
and a.name = p_name
group by a.a_id, a.name) t2,
(select value from e where e.valname = 'test') t3
where t1.a_id = t2.a_id
and t1.s1 - t2.s2 < t3.value
create table A (
id number(4);
name varchar2(32)
);create table B(
id number(4),
b_area number(32);
);create table c (
a_id number(4),
B_id number(4)
);create table d (
a_id number(4),
d_area number(32)
);create table e(
valname varchar(32),
value number(18)
);传name到a表查出a_id用id去c中查b_id然后去b表中查出b_area并求和
同时a_id 闯入d表中查询d_id并求和
然后再将两个和求差,并要求差值小于e表中valname为test的value值
然后在将满足以上条件的a表中的信息返回select t1.a_id, t1.name, t1.s1 - t2.s2
from (select a.a_id, a.name, sum(b.b_area) s1
from a, b, c
where a.a_id = c.a_id
and c.b_id = b.id
and a.name = p_name
group by a.a_id, a.name) t1,
(select a.a_id, a.name, sum(d.d_area) s2
from a, d
where a.a_id = d.a_id
and a.name = p_name
group by a.a_id, a.name) t2,
(select value from e where e.valname = 'test') t3
where t1.a_id = t2.a_id
and t1.s1 - t2.s2 < t3.value
谢谢~~