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

字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......

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

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

mysql区没高手 - MS-SQL Server / 基础类

我觉得mysql和sqlserver有共同的地方:
有个问题是关于表的锁问题:
进程A 进程B
select * from user where id in lock share mode(共享锁)
&nb ......

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号