我在MS Access中有一个表,如:
表
+-----+-----+-----+
| 1st | 2nd | 3rd |
+-----+-----+-----+
| A | 1 | 100 |
| A | 2 | 200 |
| A | 3 | 300 |
| B | 1 | 100 |
| B | 2 | 200 |
| B | 3 | 300 |
| C | 1 | 100 |
| C | 2 | 200 |
| C | 3 | 300 |
+-----+-----+-----+
现在,我想从第3列中读取值,对其进行某种处理,然后将它们存储在另一个表中,例如:
摘要
+-----+---------+---------+
| 1st | 2nd | 3rd |
+-----+---------+---------+
| A | 100/200 | 200/300 |
| B | 100/200 | 200/300 |
| C | 100/200 | 200/300 |
+-----+---------+---------+
换句话说,对于summary.2nd
,这意味着:
select table.3rd FROM table where table.1st = A AND table.2nd = 1
除以
select table.3rd FROM table where table.1st = A AND table.2nd = 3
有人可以给我提示如何做到这一点吗?
也许是VBA / ADO Recordset等?
答案 0 :(得分:2)
一种方法是条件聚合:
if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
iv.setImageBitmap(bitmap);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byteArray = stream.toByteArray();
inputStream=new ByteArrayInputStream(byteArray);
} catch (IOException e) {
e.printStackTrace();
}
}
答案 1 :(得分:0)
尝试使用此SQL
INSERT INTO Summary
SELECT DISTINCT a.[1st],
a.[3rd] / b.[3rd] AS [2nd],
a.[3rd] / c.[3rd] AS [3rd]
FROM ((tbl AS a
INNER JOIN tbl AS b
ON a.[1st] = b.[1st])
INNER JOIN tbl AS c
ON a.[1st] = c.[1st] )
WHERE a.[2nd] = 1
AND b.[2nd] = 2
AND c.[2nd] = 3
答案 2 :(得分:0)
这是使用计算的加入条件的另一种选择:
select
t1.[1st],
t1.[3rd]/t2.[3rd] as [2nd],
t2.[3rd]/t3.[3rd] as [3rd]
from
(
[table] t1 inner join [table] t2
on t1.[1st] = t2.[1st] and t1.[2nd] = t2.[2nd]-1
)
inner join [table] t3
on t1.[1st] = t3.[1st] and t1.[2nd] = t3.[2nd]-2
由于2nd
列的值1、2和3没有经过硬编码,因此这适用于2nd
列中的值依次相差1的任何三个整数。
将[table]
更改为表格名称。