SELECT
个数=(select count(单位名称) from A where year(日期)='2005') ,
总水量=(select Sum(数量) from A where year(日期)='2005'),
论证个数=(select count(项目名称) from B where year(日期)='2005')
from A,B
个数=(select count(单位名称) from A where year(日期)='2005') ,
总水量=(select Sum(数量) from A where year(日期)='2005'),
论证个数=(select count(项目名称) from B where year(日期)='2005')
from A,B
insert t_a
select 'QW',20,'2005-02-12' union all
select 'CD',14,'2004-04-03'
create table t_b (proj_name varchar(10),dt datetime)
insert into t_b
select 'SW','2005-03-21' union all
select 'ER','2004-08-14' union all
select 'ee','2005-06-15'declare @year int
set @year=2005SELECT 个数=(select count(unit) from t_a where datepart(year,dt)=@year)
,总水量=(select sum(qty) from t_a where datepart(year,dt)=@year)
,论证个数=(select count(proj_name) from t_b where datepart(year,dt)=@year) drop table t_a,t_b/*
个数 总水量 论证个数
----------- ----------- -----------
1 20 2(所影响的行数为 1 行)*/
distinct
个数=(select count(单位名称) from A where year(日期)='2005') ,
总水量=(select Sum(数量) from A where year(日期)='2005'),
论证个数=(select count(项目名称) from B where year(日期)='2005')
from A,B