日期:2014-05-16 浏览次数:20639 次
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/