sql - 如何在sql中查找特定单元格的行号和列号?
问题描述
我在 SQL 数据库中有一个表,我想找到像坐标这样的单元格的位置,反之亦然。这是一个例子:
0 1 2 3
1 a b c
2 g h i
3 n o j
当我要求时i
,我想得到row=2 and column=3
。当我要求一个单元格时row=2 and column=3
,我想得到i
。
解决方案
您需要将矩阵存储在表中,指定这样的列和行
create table matrix (
row int,
column int,
value varchar2(20)
);
然后你像这样插入你的数据
insert into matrix values (1, 1, 'a');
insert into matrix values (1, 2, 'b');
//and so on.
然后你可以使用两个查询简单地找到你需要的东西
select column, row from matrix where value = 'i';
select value from matrix where column = 2 and row = 3;
推荐阅读
- email - 使用 GMail API 发送时如何设置显示名称?
- reactjs - React js 简单钩子效果
- c# - 如何使其他类可以访问此 var?
- python - 如何在 Flask 中实现基于角色的访问控制?
- python - 加载 tensorflow_datasets 时出错:Google 云出错
- spring-boot - 休眠方法验证并不总是有效
- opencv - tensorflow 2.0 中有 cv2 findcontours 和 boundingRect 吗?
- arrays - 如何在 C 中替换文本文件中的字符串/短语
- awk - 如何使用 awk 解析 sun solaris 上的测试文件
- firebase - 避免在 Firebase 身份验证迁移中注销用户