易截截图软件、单文件、免安装、纯绿色、仅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

多谢


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

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

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

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 ......

SQL不明白 - MS-SQL Server / 应用实例

查询学生平均成绩及其名次 
  SELECT 1+(SELECT COUNT( distinct 平均成绩) 
  from (SELECT S#,AVG(score) AS 平均成绩 
  from SC&n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号