sql语句难题(100分)

S

saisi

Unregistered / Unconfirmed
GUEST, unregistred user!
如何实现用一个语句实现:
select count(*) into acount from 表a;
select count(*) into bcount from 表b;
最后要得到acount+bcount。
但是现在要用一个语句实现。
 
select count(a.*) + count(b.*) x from a,b;
 
select (select count(*) from 表a)+(select count(*) from 表b)
 
給分吧,完全正確:
select sum(num) as num from (select count(*) as num from bprod union select count(*) as num from bcust)aa
 
對不起:改下:
給分吧,完全正確:
select sum(num) as num from (select count(*) as num from 表a union select count(*) as num from 表b)aa
 
select (select count(*) from a) + (select count(*) from b) as allcount
试试这样子行不行
 
SELECT DISTINCT (SELECT COUNT(*)
FROM 表a) +
(SELECT COUNT(*)
FROM 表b)
FROM 表a

給分吧﹐100%准確
 
我的后台数据库是mysql
 
select sum(num) as num from
(select count(*) as num from a表
union
select count(*) as num from b表)aa //aa为你取的随意的名称,只是语法的需要
 
问题还是没有解决。
 
MYSQL和SQL在語法方面應該是一樣的
這樣試不行嗎?
select (select count(*) from 表a)+(select count(*) from 表b)
 
真的不行
 
由于Mysql不支持嵌套查询
你的要求基本上不能通过一个SQL语句实现
放弃你的想法吧
 
可能是吧。
 
顶部