当前位置: 代码迷 >> 其他数据库 >> SQLITE3 怎么把相同的ID列举出来
  详细解决方案

SQLITE3 怎么把相同的ID列举出来

热度:175   发布时间:2016-05-05 08:15:29.0
SQLITE3 如何把相同的ID列举出来
例如:
data表:
id      num
1        23
1         43
1        12
2        5
2         87
读出:
1    23  43  12  
2     5    87
在不知道ID号码的情况,自动把相同ID列举出来?

另外还有个问题- - 
根据一个表中的表名、字段名查询
例如:
A表:
id    database_name   column_name
1       other_A                    number

other_A 表:
number         text
10                    helloworld


我是这样查询的:

select '(select column_name from A where id=1)' from (select  database_name from A where id=1); 

这样查询出这个字段column_name的值出来,请问要怎么改!?
------解决思路----------------------
select id
from data表:
group by id
having count(*)>1
------解决思路----------------------
引用
根据一个表中的表名、字段名查询
例如:
A表:
id    database_name   column_name
1       other_A                    number

other_A 表:
number         text
10                    helloworld
这个无法在数据库中实现,除非愿意下载修改SQLITE的源代码添加这个功能。 一般是自己在程序中实现。
------解决思路----------------------
select *
from 
data表:
where id in (select id
from data表:
group by id
having count(*)>1)
------解决思路----------------------
3.6以上
select id,group_concat(num) from tt group by id