SQL:获取列和最后一个条目的总和

时间:2017-05-10 08:10:38

标签: mysql

我有两张桌子加在一起:

    SELECT 
        type, 
        name,
        SUM(value) as total_value,
        target,
        target_month,
        operator,
        SUM(value_1) as total_value1,
        AVG(average_of_total) as average
    FROM
        (SELECT 
            stats.`type`, stat_type.`target`, stat_type.`target_month`, stat_type.`operator`, stats.`monthly`, stats.`value`, stats.`value_1`, stats.`created_at`, `name`, stats.`average_of_total`   
        FROM 
            tefl_stats_customer as stats 
        JOIN 
          tefl_stats_customer_type as stat_type 
        ON 
          stats.`type` = stat_type.`id`) AS all_data
    WHERE
        created_at BETWEEN '20147-05-09 00:00:00' AND '2017-05-10 23:00:00' AND monthly = 0
    GROUP BY `type` 

目前正在回归:

    | type | Name       | total_value     | target     | target_month     | operator     | total_value1      | average      |
    |   12 | English    | 3,378           | 400        | 8000             | <=           | 0                 | 0            |
    |    9 | Chinese    | 314             | 24         | 0                | =            | 426               | 2.03698      |
    |    1 | Japanese   | 374             | 5          | 0                | <            | 78                | 6.5          |

目前,正如您所看到的那样,&#39; SUM() total_value

价值见表: tefl_stats_customer 。这个表有几千行。

如何获取上述查询中的最后一行并将其输出为 last_entry

0 个答案:

没有答案