首页 > 解决方案 > 如何在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

标签: sqloracleoracle-sqldeveloper

解决方案


您需要将矩阵存储在表中,指定这样的列和行

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;

推荐阅读