1

id (PK)我有一个包含、tid (FK)lid(FK)和列的表status (Varchar)。每个tid都有几个lid,每个lid都有一个status:“完成”或“正在进行”。

我想获取每个 的状态tid,其中 atid的状态是:如果所有状态lid为“完成”,tidtid状态为“完成”,如果任何lid状态为“进行中”,则tid状态为“进行中”。

这是我到目前为止所做的:

st2=con.createStatement();
String QueryString2 = "SELECT status from lo_status where topic_id='"+topicid+"'";
rs2 = st2.executeQuery(QueryString2);
while (rs2.next()) {
    status=rs2.getString(1);
}

if(status == null){
    status="Pending";
}
else if(status.equals("Finished")){
    status="Finished";
}else{
    status="Ongoing";
}

4

2 回答 2

0

Do something like the following.

SELECT count(rowid) total from lo_status where topic_id='"+topicid+"' and status="Finished";

If total = 0, the status is finished, else it is ongoing.

于 2013-04-03T04:01:08.590 回答
0

You can try the Following Query.

Select  count(status) As total  from lo_status where topic_id='"+topicid+"' and status =ongoing";
if(total>0){
 status="OnGoing";
}else
{
 status="Finished";
}

You can try it and If any query then asked.

于 2013-04-03T04:05:03.500 回答