Вниз
Скачать: CL | DM;

связывание таблиц   Найти похожие ветки 

← →
perov ©   (2002-02-20 10:33) [0]

есть три таблицы (скажем счета, приход, расход). как правильно составить запрос, чтобы выбиралось суммарное движение по ВСЕМ счетам, а не только по тем, информация по которым есть и в приходе и в расходе (если движений не было, то должен выбраться 0)


← →
xcb   (2002-02-20 10:44) [1]

подробнее о структуре если можно...

а вообще примерно так

select a.id_shet, ss.name, a.p_sum , a.r_sum, a.p_sum - a.r_sum ost_sum
from
(select s.id_shet, sum (p.summ) p_sum, sum (r.summ) r_sum
from shet s, prixod p, rasxod r
where s.id_shet = p.id_shet (+)
and s.id_shet = r.id_shet (+)
group by s.id_shet) a, shet ss
where a.id_shet = ss.id_shet



← →
xcb   (2002-02-20 10:48) [2]

да... забыл про нули...
не sum (p.summ) p_sum
a nvl(sum (p.summ), 0) p_sum
и nvl(sum (r.summ), 0) r_sum
...


← →
perov ©   (2002-02-20 11:08) [3]

accounts (id numeric, name char(10), ........)
payments (accid numeric, odate date, summa numeric (15,2), type char (1), .....)
calculations (accid numeric, docdate date, forpayment numeric (15,2), type char(1), ..... )


← →
perov ©   (2002-02-20 12:51) [4]

запрос работает,
но если я дабавляю условия, например, по дате, то запрос выдает неверные данные :(((


← →
xcb   (2002-02-20 15:37) [5]

select a.id_shet, ss.name, a.p_sum , a.r_sum, a.p_sum - a.r_sum ost_sum
from
(select s.id_shet,
nvl(sum (p.summ), 0) p_sum,
nvl(sum (r.summ), 0) r_sum
from shet s,
(select id_shet, sum(summ) from (select id_shet, summ
from prixod where docdate between :begdat and :enddat)) p,
(select id_shet, sum(summ) from (select id_shet, summ
from rashod where docdate between :begdat and :enddat)) r
where s.id_shet = p.id_shet (+)
and s.id_shet = r.id_shet (+)
group by s.id_shet) a, shet ss
where a.id_shet = ss.id_shet

где :begdat и :enddat переменные соотв начало и конец периода...



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.007 c
1-66823
Michael C
2002-03-06 09:32
2002.03.21
Если StrToInt глючит,


1-66837
dolmat
2002-03-06 12:22
2002.03.21
печать подобно DOS


1-66863
fishka
2002-03-04 10:51
2002.03.21
Компонент ChartFX и цвета графиков


1-66839
MystiX
2002-03-07 20:24
2002.03.21
XP стиль


14-66994
Andrey
2002-02-06 18:15
2002.03.21
Вкладка Servers




   Наверх