select rowid = identity(int,1,1),数量,年份 into #temp from table
解决方案 »
- 安装“Microsoft SQL Server 2005 Express Edition”总是 INI 文件无效
- SQL 2000 被人恶意卸载,能查记录吗?
- 表格旋转/转置/交叉表
- 问个简单的查询语句
- 分类字段切割查找分类,不正确,不知为什么,请高手检查下
- |zyciis| 我用分页控件进我的表内容进行分页,那现在我想知道某一个ID号到底在哪一页中呢 谢谢 急
- 请教如何写这个查询语言,很简单的,我是新手
- 如何用select*from语句
- 请教:一般性网络错误
- 如何在sql server 数据库中定时执行程序,50分相赠
- 如何设置网站上SQl Server数据库安全?
- 如何将SQLSERVER中的binary类型转换为int类型
from 基本表
where ((datediff(year,cssj,'2005-01-01')=60) and (xb='男')) or
((datediff(year,cssj,'2005-01-01')=55) and (xb='女'))
union all
select count(1) as 总数,'2006' as 年份
from 基本表
where ((datediff(year,cssj,'2005-01-01') between 60 and 61) and (xb='男')) or
((datediff(year,cssj,'2005-01-01') between 55 and 56) and (xb='女'))
union all
select count(1) as 总数,'2007' as 年份
from 基本表
where ((datediff(year,cssj,'2005-01-01') between 60 and 62) and (xb='男')) or
((datediff(year,cssj,'2005-01-01') between 55 and 57) and (xb='女'))
insert @t select 120,2005 union all
select 190,2006 union all
select 240,2007 select rowid = identity(int,1,1),sl,nf into #temp from @t
select * from #temp
select aa.sl - b.sl2 ,aa.nf,aa.rowid from #temp aa,
(select isnull(sl,0) as sl2,rowid from #temp ) b
where aa.rowid *= b.rowid +1drop table #temp/* nf rowid
----------- ----------- -----------
120 2005 1
70 2006 2
50 2007 3*/
insert into #t values(70,2006)
insert into #t values(50,2007)
select isnull((select sum(a) from #t where b<tt.b),(select min(a) from #t)),b
from #t tt
order by b