易截截图软件、单文件、免安装、纯绿色、仅160KB

求个SQL语句 - MS-SQL Server / 疑难问题

A表:
thread_id msg_box read
1 4 1
2 1 1
3 1 0
4 1 1

B表:
_id read
2 0
3 1
4 1
5 1
6 0

我想取出A表中read为1与B表中read为1的总数
我的SQL语句是这样:
select count(*)+(select count(*) from b where read=1)
from a
where read=1

这样确实可以取出来,但是太笨了。。。有没有什么好的方法吗?
补充一下,两表之间没有主键与外键的关系

引用
A表:
thread_id msg_box read
1 4 1
2 1 1
3 1 0
4 1 1

B表:
_id read
2 0
3 1
4 1
5 1
6 0

我想取出A表中read为1与B表中read为1的总数
我的SQL语句是这样:
select count(*)+(select count(*) from b where read=1)
fro……
这种方法不会笨


引用

引用楼主 furlxy 的回复:
A表:
thread_id msg_box read
1 4 1
2 1 1
3 1 0
4 1 1

B表:
_id read
2 0
3 1
4 1
5 1
6 0

我想取出A表中read为1与B表中read为1的总数
我的SQL语句是这样:
select count(*)+(select count(*) from b……

-。-是嘛

引用
SQL code
select
count(1)
from
(
select read from a
union all
select read from b
)t

多谢


相关问答:

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

SQL server分解XML - MS-SQL Server / 应用实例

下面是XML初始文件内容
XML code:
<upd:Update xmlns:lar="http://schemas.microsoft.com/msus/2002/12/LogicalApplicabilityRules" xmlns:cmd="http://schemas.microsoft.com/msus/2002/12/Up ......

SQL语句问题 - MS-SQL Server / 疑难问题

请教高手:
 以下是数据库中的三条记录,英文为字段名称  
  id planname TaskBeginTime Status
329 2010年03 ......

关于Vb中sql语句的写法(100分) - Java / Web 开发

求个vb中的sql语句的写法,次sql语句的用法是分页程序
我写的如下:其中A是用来接收每页显示的记录的条数,B是用来接收显示的当前的页面.
sqltext="select top A * from log where id not in(select top ( ......

sql 问题 - MS-SQL Server / 基础类

需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号