首先传一个ID=1001去数据库 查询 PID=1001的所有记录
然后把查询出来的所有记录ID当成PID继续查询符合条件的记录这是MYSQL语句 不过查不到记录
select ftm_name from functionitem where ftm_pid=(select ftm_ftm_id from functionitem where ftm_pid=1001)反正就是这样的意思 我怎么实现呢
然后把查询出来的所有记录ID当成PID继续查询符合条件的记录这是MYSQL语句 不过查不到记录
select ftm_name from functionitem where ftm_pid=(select ftm_ftm_id from functionitem where ftm_pid=1001)反正就是这样的意思 我怎么实现呢
ftm_ftm_id 这个是里面选出来的字段
而外面 where ftm_pid =
id 和 pid 有相等的数据吗?
是的 他们是级联的关系二楼指出了我SQL语句的错误,但是不想用语句实现,想用程序实现,该怎么做呢
说的就是这个意思
while(list.size()>0){
for(int i=0;i<list.size();i++){
ftm=(Functionitem)list.get(i);
list=ftmservice.getftmtwo(myconn,ftm.getFtm_ftm_id());
}
}
这种写法就行,如果你想取不同a,b表的不同记录,就把前面的字段加上(as 名称) 就行了
这种写法就行,如果你想取不同a,b表的不同记录,就把前面的字段加上(as 名称) 就行了,上帖拉了个a,哈哈
=============================
ID name PID
========================
1001 张山1 1000
1001 张山2 1000
1002 张山3 1000
1003 张山4 1000
1004 张山5 100010011 张山6 1002
10012 张山7 1002
10013 张山8 1002
10014 张山9 100210015 张山10 1003
10016 张山14 1003
10017 张山15 1003
10018 张山16 100310019 张山17 10014
10020 张山17 10014
10021 张山18 10014
10022 张山19 1001410023 张山19 10019
10024 张山19 10019
10025 张山19 1001910026 张山19 10018
10027 张山19 10018==========================================
我传一个PID=1000 查询出pid=1000的记录后
1001 张山1 1000
1001 张山2 1000
1002 张山3 1000
1003 张山4 1000
1004 张山5 1000=======================
把它们的ID 1001,1002,1003当成PID继续查询
查询PID=1001,1002,1003,如此类推,代码怎么实现..................
List list1 = new ArrayList();
//List list2 = new ArrayList();
Map map = new HashMap();
String PID = "",ID = "";
public void testList(){
sql = "select ID from table where PID= "+PID;
ps = con.prepareStatement(sql);
list1 = ps.executeQuery();
for(int i=0; i<list1.size();i++){
sql = "select * from tabel where ID=" + list1.get(i);
ps = con.prepareStatement(sql);
//list2 = ps.executeQuery();
map.put(list1.get(i),ps.executeQuery());
}
}
public void testMap(String ID)
for(Iterator it = map.entrySet().iterator();it.hasNext();){
Map.Entry entry = (Map.Entry)it.next();
Object key = entry.getKey();
Object val = entry.getValue();
if(key.equals(ID) )
{
System.out.println(val); //此时就是为"ID="+ ID的那条数据啦
}
}
}
//没有经过实验,我想应该可以吧。有错误大家给指出来。。