解决方案 »
- 大哥们推荐几本数据挖掘的书把
- 这样的数据结构怎样设计TABLE最优
- 问个基础的题目,请指教
- 如何将记录集分段显示?
- 难题求教:在SqlServer中如何直接得到中文姓的对应字母?例如:陈->C ; 张->Z; 谢谢!!!
- 又出现问题了,高手再帮帮忙
- 找一本书!!!!
- 送分 100 分, sql server2000, 一个数据库内有 50万 个表.......
- 超过255的字段的内容,在bcp out的时候会丢失,但是用bcp.exe没有问题,因为它的前导符为两个字节表示长度,而用db-library的bcp_exec生
- 问个SQL修改脚本的问题?
- 数据库复制 和 CDC
- mssql 里面的convert函数
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-05-07 14:58:22
-- Version:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
-- Apr 2 2010 15:48:46
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([id] nvarchar(4),[weight] int,[count] int,[v1] nvarchar(8),[v2] nvarchar(8))
insert [huang]
select 'a',500,10,'a500','a500' union all
select 'a',200,20,'a','a' union all
select 'b',500,10,'b500','b500' union all
select 'b',100,10,'b5','b5' union all
select NULL,20,20,'20','20' union all
select NULL,20,20,'20','20'
--------------生成数据--------------------------select id,MAX([weight])[weight],SUM([count])[count],MAX([v1])[v1],MAX([v2])[v2]
from [huang]
WHERE id IS NOT NULL
GROUP BY id
UNION ALL
SELECT *
FROM dbo.huang
WHERE id IS NULL
----------------结果----------------------------
/*
id weight count v1 v2
---- ----------- ----------- -------- --------
a 500 30 a500 a500
b 500 20 b500 b500
NULL 20 20 20 20
NULL 20 20 20 20
*/