这样写也行。 select aa.xxx,bb.xxx,cc.xxx,dd.xxx from a aa,b bb,c cc,d dd where aa.user_name=bb.user_name and aa.user_name=cc.user_name and aa.user_name=dd.user_name and 加上你的查询条件。不知道你的user_name是怎么对应的,where条件还可以这样 where aa.user_name=bb.user_name and bb.user_name=cc.user_name and cc.user_name=dd.user_name and .............
大哥们 我这个查询的时候 需要 count() 好几次。。怎么办。。
select count(*) from a aa,b bb,c cc,d dd where aa.user_name=bb.user_name and aa.user_name=cc.user_name and aa.user_name=dd.user_name and ......或些个存储过程调用
就是把这几个语句综合起来select count(*) from a where user_name = 'xuemiao'select count(*) from a where supply_authentication = 'y' and user_name = 'xuemiao' select count(*) from b where user_name = 'xuemiao'select count(*) from b where supply_authentication = 'y' and user_name = 'xuemiao' select count(*) from c where user_name = 'xuemiao'select count(*) from c where supply_authentication = 'y' and user_name = 'xuemiao' select count(*) from d where user_name = 'xuemiao'select count(*) from d where supply_authentication = 'y' and user_name = 'xuemiao'
不会写存储过程就重复执行调用吧。 sql1语句 "select count(*) from a aa,b bb,c cc,d dd where aa.user_name=bb.user_name and aa.user_name=cc.user_name and aa.user_name=dd.user_name and aa.aa_session = " + session + " and bb.bb_session = " + session + " and cc.cc_session = " + session + " and dd.dd_session = " + session;sql2语句 "select count(renzheng) from a aa,b bb,c cc,d dd where aa.user_name=bb.user_name and aa.user_name=cc.user_name and aa.user_name=dd.user_name and aa.aa_session = " + session + " and bb.bb_session = " + session + " and cc.cc_session = " + session + " and dd.dd_session = " + session;
同意 Yzw_2006() 用union
select * into #tempT from a as aa (nolock) join b as bb (nolock) on aa.username = bb.username join c as cc (nolock) on bb.username = cc.username join d as dd (nolock) on cc.username = dd.username where dd.username = @username //**then you can calculate the value you want*** select count(1) from #tempTi don't know the condition you count for, so please add it yourself,i think this quality will be better if you user temp table.
有的话用inner join如果表结构都一样就用 union 连接
select aa.xxx,bb.xxx,cc.xxx,dd.xxx from a aa,b bb,c cc,d dd where aa.user_name=bb.user_name and aa.user_name=cc.user_name and aa.user_name=dd.user_name and 加上你的查询条件。不知道你的user_name是怎么对应的,where条件还可以这样
where aa.user_name=bb.user_name and bb.user_name=cc.user_name and cc.user_name=dd.user_name and .............
————————————————————————————————————
从session 里面区一个值 让a,b,c,d表里面的值得都等于这个然后count()a,b,c,d表里面的信息, 在count(renzheng)a,b,c,d表里面的信息也就是count()两次
select count(*) from b where user_name = 'xuemiao'select count(*) from b where supply_authentication = 'y' and user_name = 'xuemiao'
select count(*) from c where user_name = 'xuemiao'select count(*) from c where supply_authentication = 'y' and user_name = 'xuemiao'
select count(*) from d where user_name = 'xuemiao'select count(*) from d where supply_authentication = 'y' and user_name = 'xuemiao'
sql1语句
"select count(*) from a aa,b bb,c cc,d dd where aa.user_name=bb.user_name and aa.user_name=cc.user_name and aa.user_name=dd.user_name and aa.aa_session = " + session + " and bb.bb_session = " + session + " and cc.cc_session = " + session + " and dd.dd_session = " + session;sql2语句
"select count(renzheng) from a aa,b bb,c cc,d dd where aa.user_name=bb.user_name and aa.user_name=cc.user_name and aa.user_name=dd.user_name and aa.aa_session = " + session + " and bb.bb_session = " + session + " and cc.cc_session = " + session + " and dd.dd_session = " + session;
用union
into #tempT
from a as aa (nolock)
join b as bb (nolock)
on aa.username = bb.username
join c as cc (nolock)
on bb.username = cc.username
join d as dd (nolock)
on cc.username = dd.username
where dd.username = @username
//**then you can calculate the value you want***
select count(1) from #tempTi don't know the condition you count for, so please add it yourself,i think this quality will be better if you user temp table.