此列是sqlite中的价格。我正在使用SELECT SUM(price) FROM example;
但是值不正确它只有5位数后跟67个数字和6个零和1,例如:34,456.670000001。该列被创建为VARCHAR。我已经尝试过数字(100)和整数但是值仍然保持不变。请指导我,因为我是db.Thanks中的菜鸟。我真的很感激帮助。
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
126,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
75,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
52,334,123.32
2,442,887.21
255,165.11
3,889.02
622.43
916.52
42.22
17,234.01
77,245.67
104,245.00
332.98
6,875.21
12,225.14
52.54
402.82
32,875.32
160,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.00
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
2,442,887.21
255,165.11
3,889.02
622.43
916.52
42.22
17,234.01
77,245.67
104,245.00
332.98
6,875.21
12,225.14
52.54
402.82
32,875.32
246,323,743.32
345,887.45
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,237,129.57
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
2,442,887.21
255,165.11
3,889.02
622.43
916.52
42.22
17,234.01
77,245.67
104,245.00
332.98
6,875.21
12,225.14
52.54
402.82
32,875.32
183,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,322,555.39
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
2,442,887.21
255,165.11
3,889.02
622.43
916.52
42.22
17,234.01
77,245.67
104,245.00
332.98
6,875.21
12,225.14
52.54
402.82
32,875.32
153,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,400,321.23
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
2,442,887.21
255,165.11
3,889.02
622.43
916.52
42.22
17,234.01
77,245.67
104,245.00
332.98
6,875.21
12,225.14
52.54
402.82
32,875.32
83,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,341,152.99
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
139,334,123.32
2,442,887.21
255,165.11
3,889.02
622.43
916.52
42.22
17,234.01
77,245.67
104,245.00
332.98
6,875.21
12,225.14
52.54
402.82
32,875.32
164,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,299,477.81
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
139,334,123.32
2,442,887.21
255,165.11
3,889.02
622.43
916.52
42.22
17,234.01
77,245.67
104,245.00
332.98
6,875.21
12,225.14
52.54
402.82
32,875.32
166,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,309,926.11
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
139,334,123.32
2,442,887.21
255,165.11
3,889.02
622.43
916.52
42.22
17,234.01
77,245.67
104,245.00
332.98
6,875.21
12,225.14
52.54
402.82
32,875.32
83,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,334,123.32
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
129,387,002.55
345,887.21
16,520.11
388,902.02
24,622.43
278,916.52
42.22
17,234.01
377,245.67
5,104,245.00
23,332.98
126,875.21
5,112,225.14
4,552.54
402.82
132,875.32
31,334,123.32
2,442,887.21
255,165.11
3,889.02
622.43
916.52
42.22
17,234.01
77,245.67
104,245.00
332.98
6,875.21
12,225.14
52.54
402.82
32,875.32
83,334,123.32
答案 0 :(得分:3)
问题是,当SQLite隐式地将这些字符串强制转换为数字时,它会截断逗号中的数字,以便它们可以对它们进行求和。例如:
sqlite> select '1,000' + '2,000';
'1,000' + '2,000'
3
您需要做的就是删除逗号。您应该可以使用replace
,然后让SQLite的默认类型转换从那里获取它:
SELECT SUM(replace(price, ',', '')) FROM example
例如:
sqlite> select replace('1,000', ',', '') + replace('2,000', ',', '');
replace('1,000', ',', '') + replace('2,000', ',', '')
3000