摘要: DECLARE@ttable(姓名varchar(10))insertinto@Tvalues('张三')insertinto@Tvalues('李四')insertinto@Tvalues('王二')insertinto@Tvalues(NULL)DECLARE@T2table(姓名varchar(10),课程varchar(10),分数int)insertinto@T2values('张三','语文',74)insertinto@T2values('张三','数学',83)ins 阅读全文
posted @ 2011-05-12 06:31 geass.. 阅读(192) 评论(0) 推荐(0) 编辑
摘要: declare @sql varchar(8000)select @sql = isnull(@sql + ',' , '') + 课程 from tb group by 课程exec ('select m.* , n.平均分 , n.总分 from(select * from (select * from tb) a pivot (max(分数) for 课程 in (' + @sql + ')) b) m , (select 姓名 , cast(avg(分数*1.0) as decimal(18,2)) 平均分 , sum(分数) 总 阅读全文
posted @ 2011-05-12 06:09 geass.. 阅读(516) 评论(0) 推荐(0) 编辑
摘要: -- specify the number of rows you want -- to delete per 'gulp':DECLARE @count intSET @count = 2000-- keep track of the number of rows-- impacted by each gulp... once it-- drops below the intended number of rows-- then you're done... DECLARE @rowcount intSET @rowcount = @count-- keep date 阅读全文
posted @ 2011-05-12 06:05 geass.. 阅读(346) 评论(0) 推荐(0) 编辑
摘要: 表table_A: 路线代码 起点 终点 起点桩号 终点桩号 Y440608 大湾 石柱 0.56 2.35 Y440608 石柱 观音桥 2.35 8.52 Y440608 观音桥 芦溪 8.52 11.98 Y440605 龙桥 磙子河 36.58 56.32现在要写一条sql 让结果这样 路线代码 起点 终点 起点桩号 终点桩号 Y440608 大湾 芦溪 0.56 11.98 Y440605 龙桥 磙子河 36.58 56.32问题分析:1、典型的自联接问题;2、首先查找同一编码下的起点最小值和最大值的两条记录;3、选择同一编码下,最小的起点和最大的终点值,自关联出一条记录;4、使用m 阅读全文
posted @ 2011-05-12 06:01 geass.. 阅读(434) 评论(0) 推荐(0) 编辑