How to SUM SQLExp query?

Hello everyone,

Please, could anyone tell me how to add sum function in the next query?

[
SQLExp('select anDiscount from the_move where ackey='''+<qReportIzpis."acKey">+''' ')
]

In the FR page i normally get anDiscount for every article, but in the next dataset I want to get sum of all articles that I've got after execution of that query.

Thanks in advance...

Comments

  • edited 3:24AM
    borispauck wrote: »
    Hello everyone,

    Please, could anyone tell me how to add sum function in the next query?

    [
    SQLExp('select anDiscount from the_move where ackey='''+<qReportIzpis."acKey">+''' ')
    ]

    In the FR page i normally get anDiscount for every article, but in the next dataset I want to get sum of all articles that I've got after execution of that query.

    Thanks in advance...

    select
    anDiscount,
    (select
    SUM(anDiscount)
    from the_move where ackey='''+<qReportIzpis."acKey">+'''
    ) AS DISCOUNT_TOTAL
    from the_move where ackey='''+<qReportIzpis."acKey">+'''

    Of course this will be quite inefficient as the totalling query will run for every row.

  • edited 3:24AM
    borispauck wrote: »
    Hello everyone,

    Please, could anyone tell me how to add sum function in the next query?

    [
    SQLExp('select anDiscount from the_move where ackey='''+<qReportIzpis."acKey">+''' ')
    ]

    In the FR page i normally get anDiscount for every article, but in the next dataset I want to get sum of all articles that I've got after execution of that query.

    Thanks in advance...

    You could get rid of the second select:

    select
    anDiscount,
    SUM(anDiscount) AS DISCOUNT_TOTAL
    from the_move where ackey='''+<qReportIzpis."acKey">+'''

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.