在SQLserver中,一般写一些存储过程能提高数据库操作效率。简单记录几个存储过程,以备查询。
一、利用一个字段进行分组求平均值、最大值、最小值;
USE [Mengtougou]
GO
/****** Object: StoredProcedure [dbo].[extracter_Site_651031] Script Date: 05/15/2015 09:48:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date: 2015-03
-- Description: <Description,,>
/*
代码编写:
--调用示例--
extracter_Site_651031 @month=7,@day=11
*/
-- =============================================
PROCEDURE [dbo].[extracter_Site_651031]
-- Add the parameters for the stored procedure here
@month nvarchar(20), -- 输入月份
@day nvarchar(20)-- 输入日份
AS
DECLARE @str nvarchar(300)
DECLARE @str1 nvarchar(300)
DECLARE @str2 nvarchar(300)
DECLARE @filename nvarchar(30)
BEGIN
----------------------------------Site_651031---------------------------------------------------
select Site_651031.站号,
AVG(MTG_2012clear.气温)as t_avg,
max(MTG_2012clear.气温)as t_max,
min(MTG_2012clear.气温)as t_min
into temp
from Site_651031 left join MTG_2012clear
on Site_651031.站号=MTG_2012clear.站号
where MTG_2012clear.月=@month and MTG_2012clear.日=@day
GROUP BY Site_651031.站号;END
set @str1='update Site_651031 s