bt 查询

时间:2008-06-10 08:34:33   来源:论坛整理  作者:  编辑:chinaitzhe
有表A,A(acolumn)

B1(acolumn,B1index)
B2(acolumn,B2index);
(B1 , B2区分不同的用途)

A中的acolumn假如在B1中,则得到B1index,再由 B1index 得到info1表的具体信息;
若在B2中,则得到B2index,再由 B2index 得到info2表的具体信息。
(info1和info2是一样的)
再循环查询A中的acolumn列。
(得到的info1和info2汇总,且每次显示10条)



网友回复:union all
分两个查询
网友回复:支持楼上
网友回复:
public int startqueryshiyongminxi(int skipnum,String cardaccount, String starttime,String endtime)
{
int ret=domysqlconn();

try{
String querysql="select card_index from card_base_info where card_id='" cardaccount "'"; //有参数cardaccount得到一个索引
ResultSet res=mysqlstmt.executeQuery(querysql);
res.next();
int cardindex=res.getInt("card_index");
res.close();



String balance_all_query="select balance_index from balance_all_info where card_index=" cardindex;
//用该索引得到另一个表balance_all_info(该表中两种卡A和卡B的信息)中的一个索引

ResultSet res_balance=mysqlstmt.executeQuery(balance_all_query);


while(res_balance.next()){
//得到 res_balance的值后 若在balance_conf中出现,则根据conf_index 查询balance_conf_account(卡A)中的信息
若在balance_voip中出现,则根据voip_index 查询 balance_voip_account(卡B)中的信息
int balanceindex=res_balance.getInt(1);

String queryofconf="select conf_index from balance_conf where balance_index=" balanceindex;
String queryofvoip="select voip_index from balance_voip where balance_index=" balanceindex;
//balance_conf balance_voip 实际上是两个过渡的表
ResultSet resofconf=mysqlstmt.executeQuery(queryofconf);

ResultSet resofvoip=mysqlstmt.executeQuery(queryofvoip);

if(resofconf.next()){

int confindex=resofconf.getInt(1);
String subquery1="from balance_conf_account where conf_index=" confindex " and start_time>'" starttime "' and start_time <'" endtime "' and end_time!='0000-00-00 00:00:00'";
querysql="select start_time,member_count,sec_to_time(unix_timestamp(end_time)-unix_timestamp(start_time)) " subquery1;
mysqlres=mysqlstmt.executeQuery(querysql);

mysqlsubstmt=mysqlconn.createStatement();
String querysqlss="select member_number from conf_join_member where conf_index=" confindex;
mysqlsubres=mysqlsubstmt.executeQuery(querysqlss);

}
else if(resofvoip.next()){
int voipindex=resofvoip.getInt(1);
String subquery2="from balance_voip_account where voip_index=" voipindex " and start_time>'" starttime "' and start_time <'" endtime "' and end_time!='0000-00-00 00:00:00'";
querysql="select start_time,member_count,sec_to_time(unix_timestamp(end_time)-unix_timestamp(start_time)) " subquery2;

mysqlsubstmt=mysqlconn.createStatement();
String querysqlss="select member_number from voip_join_member where voip_index=" voipindex;
mysqlsubres=mysqlsubstmt.executeQuery(querysqlss);

}

}

ret=0;

}catch (Exception e){
System.out.println("Error:" e.toString());
ret=-10;
}

return ret;
}


写了这些,望大家指正。
网友回复:B1和B2联合union
后与A连接,与info信息连接就可以了
网友回复:
引用 4 楼 jdlsfl 的回复:
B1和B2联合union
后与A连接,与info信息连接就可以了

YES
网友回复:
引用 1 楼 laorer 的回复:
union all
分两个查询
关键字:bt,查询,
上一篇:jsp框架问题

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面