Announcement

Collapse
No announcement yet.

Using MySQL Formulas in Summary view

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using MySQL Formulas in Summary view

    Hi,

    I can not be able to have a summary view when i have formulas in my mysql query.

    For example, how can i use summary for this query ( a1 and a2 are field)

    SELECT
    `x` , Month,
    sum(a1) as 'a1',
    sum(a1) / sum(a2) * 100 as 'a3'

    FROM `table` group by `x`, Month


    Edit :
    Because summary view add another 'sum' (ex: sum(sum(a1) / sum(a2) * 100 as 'a3' ) and sum in sum is not ok for mysql syntax.
    Last edited by egercek; 03-13-2015, 10:40 AM.

  • #2
    Esto te puede ayudar

    Code:
    SELECT field1,
               month,
               sum((a1 / a2) * 100) as 'a3'
    FROM
    (SELECT 
             `x` as field1, 
             Month as month, 
             sum(a1) as 'a1', 
             sum(a2) as 'a2'
    
    FROM `table` 
    group by `x`, Month ) as view_final

    Comment


    • #3
      I will try.

      Gracias..

      Comment


      • #4
        Originally posted by egercek View Post
        Hi,

        I can not be able to have a summary view when i have formulas in my mysql query.

        For example, how can i use summary for this query ( a1 and a2 are field)

        SELECT
        `x` , Month,
        sum(a1) as 'a1',
        sum(a1) / sum(a2) * 100 as 'a3'

        FROM `table` group by `x`, Month


        Edit :
        Because summary view add another 'sum' (ex: sum(sum(a1) / sum(a2) * 100 as 'a3' ) and sum in sum is not ok for mysql syntax.
        Views are your friends
        /Giuseppe

        Professional Scriptcase Services
        Some Customers opinions

        Comment

        Working...
        X