Skip to content

Instantly share code, notes, and snippets.

@hackimov
Created November 20, 2020 12:28
Show Gist options
  • Save hackimov/bde7f823934f869a901d3e64143f4805 to your computer and use it in GitHub Desktop.
Save hackimov/bde7f823934f869a901d3e64143f4805 to your computer and use it in GitHub Desktop.
DOCUMENT TOTAL SUM UPDATE SQL
UPDATE documents set document_total_sum = tmp_sel.summa FROM
(SELECT documents.document_id, cast(sum(vat_total_sum) as numeric(20,2)) as summa from documents LEFT JOIN value_params vp on documents.document_id = vp.document_id
LEFT JOIN goods g on vp.value_param_id = g.value_param_id
WHERE param_id = '78624016-1195-4301-8576-cfabead6c9c9' group by documents.document_id) as tmp_sel
WHERE documents.document_id = tmp_sel.document_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment