0

此列是 sqlite 中的价格。我正在使用SELECT SUM(price) FROM example; 但该值不正确,它只是 5 位数字,后跟 67 个数字和 6 个零和 1,例如: 34,456.670000001 。该列是作为 VARCHAR 创建的。我尝试了 numeric(100) 和 Integer,但值仍然保持不变。请指导我完成,因为我是 db 中的菜鸟。再次感谢。我非常感谢您的帮助。

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 
4

1 回答 1

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
于 2012-12-24T07:16:39.910 回答