日期:2014-05-16 浏览次数:20496 次
SELECT FIELD1, FIELD2,FIELD3,
FIELD4=STUFF((SELECT ','+[type] FROM AA表 t WHERE FIELD1=t1.FIELD1 and FIELD2=t1.FIELD2 and FIELD3=t1.FIELD3 FOR XML PATH('')), 1, 1, ''),
sum(数量) as 数量
FROM AA表 t1
GROUP BY FIELD1, FIELD2,FIELD3
IF EXISTS(SELECT NAME FROM sys.objects AS o WHERE o.name = 'test')
DROP TABLE test
GO
CREATE TABLE test(field1 VARCHAR(10) , field2 NVARCHAR(1) , field3 NVARCHAR(1),field4 NVARCHAR(10) , qty INT)
GO
INSERT INTO test
SELECT '2050*700' , N'只' , N'左' , N'1号位' , 1