|
|
|
| Здравствуйте!
Имеется запрос:
SELECT DISTINCT MyQuery.year_, MyQuery.month_, MyQuery.debet, MyQuery.kredit, SumField(ostatok) AS saldo
FROM (SELECT year(dt) AS year_, month(dt) AS month_, sum(debet_) AS debet, sum(kredit_) AS kredit, debet-kredit AS ostatok
FROM (SELECT dt, a.id, nz(max(a.amount),0) AS debet_, Sum((Nz(b.amount,0)-Nz(return,0))*price) AS kredit_ FROM oper_dealer AS a
LEFT JOIN oper_dealer_sub AS b
ON a.id=b.oper_dealer_id
GROUP BY dt, a.id) AS t
GROUP BY year(dt), month(dt)) AS MyQuery
WHERE SumField()=0;
|
где SumField:
Public Function SumField(Optional Var) As Double
Static D As Double
If IsMissing(Var) Then
D = 0
Else
D = D + Nz(Var, 0)
End If
SumField = D
End Function
|
Помогите сделать его быстрее.
Спасибо! | |
|
| |
|
|
|
|
вы же группировку же применяете воложенных
неужели все равно ещё и дистинкт нужен? | |
|
| |
|
|
|
| myquery.year
дальше не читал | |
|
| |