如何汇总2具有不同日期和分组的列 [英] How Do I Summary 2 Column With Different Date And Group By

查看:71
本文介绍了如何汇总2具有不同日期和分组的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我得到了一张桌子的例子

桌子

=====

id_user |股权|时间表

123 | 2000年| 2015-09-29

124 | 2000年| 2015-09-29

125 | 2000年| 2015-09-29

126 | 2000年| 2015-09-29

127 | 2000年| 2015-09-29

123 | 3000 | 2015-09-28

124 | 3000 | 2015-09-28

125 | 1000 | 2015-09-28

126 | 1000 | 2015-09-28

127 | 2000年| 2015-09-28



我想要的是查询后的这样的东西,



id_user |总结

123 | -1000

124 | -1000

125 | 1000

126 | 1000

127 | 0



所以公式是从第29天起的股权 - 从28日起的股权

我该怎么做?

谢谢。请告诉我查询。

here i got an example for the table
TABLE
=====
id_user | equity | schedule
123 | 2000 | 2015-09-29
124 | 2000 | 2015-09-29
125 | 2000 | 2015-09-29
126 | 2000 | 2015-09-29
127 | 2000 | 2015-09-29
123 | 3000 | 2015-09-28
124 | 3000 | 2015-09-28
125 | 1000 | 2015-09-28
126 | 1000 | 2015-09-28
127 | 2000 | 2015-09-28

what i want is something like this after the query,

id_user | summary
123 | -1000
124 | -1000
125 | 1000
126 | 1000
127 | 0

so the formula is the equity from date 29 - the equity from date 28
how can i do that ?
thanks. please teach me the query.

推荐答案

如果日期已修复或者你要将这些文件传递给查询,那么你可以试试这个 -

If date are fixed or you are going to pass these someway to the query then you can ctry this-
SELECT T1.id_user, T1.equity-T2.equity AS summary
FROM YourTable T1
LEFT JOIN YourTable T2 ON T1.id_user=T2.id_user
WHERE T1.schedule='2015-09-29' AND T2.schedule='2015-09-28'





如果你想让它变得动态,请告诉我。



希望,它会有所帮助: )



If you want it to make dynamic, please let me know.

Hope, it helps :)


如果场景变成这样,该怎么办?



id_user |股权|时间表

123 | 2000年| 2015-09-29

124 | 2000年| 2015-09-29

125 | 2000年| 2015-09-29

126 | 2000年| 2015-09-29

127 | 2000年| 2015-09-28

123 | 3000 | 2015-09-28

124 | 3000 | 2015-09-28

125 | 1000 | 2015-09-28

126 | 1000 | 2015-09-28

127 | 2000年| 2015-09-27





id_user |摘要|时间表

123 | -1000 | 2015-09-29

124 | -1000 | 2015-09-29

125 | 1000 | 2015-09-29

126 | 1000 | 2015-09-29

127 | 0 | 2015-09-28



我该怎么做?



谢谢。
what if the scenario become like this,

id_user | equity | schedule
123 | 2000 | 2015-09-29
124 | 2000 | 2015-09-29
125 | 2000 | 2015-09-29
126 | 2000 | 2015-09-29
127 | 2000 | 2015-09-28
123 | 3000 | 2015-09-28
124 | 3000 | 2015-09-28
125 | 1000 | 2015-09-28
126 | 1000 | 2015-09-28
127 | 2000 | 2015-09-27


id_user | summary | schedule
123 | -1000 | 2015-09-29
124 | -1000 | 2015-09-29
125 | 1000 | 2015-09-29
126 | 1000 | 2015-09-29
127 | 0 | 2015-09-28

how can i do that ?

thanks.


这篇关于如何汇总2具有不同日期和分组的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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