SQLite累积和和WHERE包含嵌套的SUBSTR()

时间:2016-11-10 03:38:48

标签: database sqlite

如何根据标题记录代码获得累积金额?

考虑:

 tbl_A:
 --------------------------------
 |  is_title  |  code  | amount |
 --------------------------------
 | 1          | "1"    |   null |
 | 0          | "11"   |     10 |
 | 0          | "12"   |     15 |
 | 1          | "13"   |   null |
 | 0          | "131"  |      3 |
 | 0          | "132"  |      3 |
 | 1          | "2"    |   null |
 | 0          | "21"   |     30 |
 | 0          | "22"   |     40 |
 --------------------------------

我想得到:

 --------------------------------
 |  code  | amount | cumulative |
 --------------------------------
 | "1"    |   null |         25 |
 | "11"   |     10 |       null |
 | "12"   |     15 |       null |
 | "13"   |   null |          6 |
 | "131"  |      3 |       null |
 | "132   |      3 |       null |
 | "2"    |   null |         70 |
 | "21"   |     30 |       null |
 | "22"   |     40 |       null |
 --------------------------------

我尝试在SELECT上对列进行别名并在嵌套SELECT的WHERE上使用它时失败。

0 个答案:

没有答案