如何在mysql中添加两行 [英] how to add two rows in mysql

查看:104
本文介绍了如何在mysql中添加两行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我在其中有一个名为temp_reading的表,其中包括以下各列:

Hi I have a table called temp_reading in this i have the following columns :

meterid consumption  total

1          100

1           150

1          200

1          300


现在我要总像


now i want the total like

meterid    consumption            total

 1             100                 100

 1             150                 250

 1             200                450

 1             300                750



我尝试了以下查询



i tried the following query

select meterid,consumption,sum(consumption) as total from temp_reading group by meterid;



请帮助我

[edit]添加了代码块[/edit]



please help me

[edit]code block added[/edit]

推荐答案

您似乎正在尝试向查询中添加运行总计. br/> 本文在SQL Server中计算简单运行总计 [ ^ ]描述有几种方法可以实现.
It looks like you are trying to add a running total to your query.
This article Calculating simple running totals in SQL Server[^] describes several ways this can be achieved.


这篇关于如何在mysql中添加两行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆