Article View: bit.databases.mssql-l
Article #222Re: subsum
From: Uri Dimant
Date: Mon, 01 Sep 2003 05:10
Date: Mon, 01 Sep 2003 05:10
70 lines
2930 bytes
2930 bytes
Hi, I have just added PK to your table. Try to avoid using reserve words like order ,name etc. CREATE TABLE #TEMP ( [ID] int not null primary key, [order] INT NOT NULL, [name] VARCHAR(10) NOT NULL, activity VARCHAR(10), [count] INT NOT NULL ) INSERT INTO #TEMP values (1,1,'mark1',NULL,0) INSERT INTO #TEMP values(2,1,'mark1','movie',5) INSERT INTO #TEMP values(3,1,'mark1','movie',4) INSERT INTO #TEMP values(4,1,'mark1','game',3) INSERT INTO #TEMP values(5,2,'mark2',NULL,0) INSERT INTO #TEMP values(6,2,'mark2','sport',3) INSERT INTO #TEMP values(7,2,'mark2','game',2) INSERT INTO #TEMP values(8,2,'mark2','game',1) SELECT * FROM #TEMP SELECT [order],[name],activity,sum([count]) FROM #TEMP where activity is not null group by [order],[name],activity drop table #temp "ricksql@yahoo.com" <u50415039@spawnkill.ip-mobilphone.net> wrote in message news:l.1062386880.1390777587@host-66-81-113-53.rev.o1.com... > #temptable (order, name, activity and count): > > 1 mark1 null 0 > 1 mark1 movie 5 > 1 mark1 game 4 > 1 mark1 game 3 > 2 mark2 null 0 > 2 mark2 sports 6 > 2 mark2 game 4 > 2 mark2 game 3 > 2 mark2 candy 2 > 3 mark3 null 0 > 3 mark3 movie 2 > 3 mark3 game 4 > 3 mark3 candy 3 > > from #temptable (above), > how to create #temptable1(below)?. > (adding same activities within an order): > > 1 mark1 movie 5 > 1 mark1 game 7 > 2 mark2 sports 6 > 2 mark2 game 7 > 2 mark2 candy 2 > 3 mark3 movie 2 > 3 mark3 game 4 > 3 mark3 candy 3 > > > > > -- > Sent by ricksql from yahoo subpart from com > This is a spam protected message. Please answer with reference header. > Posted via http://www.usenet-replayer.com/cgi/content/new
Technical Details
Message-ID:
<OzK3o8DcDHA.1744@TK2MSFTNGP12.phx.gbl>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!msrtrans1!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gblReferences:
<l.1062386880.1390777587@host-66-81-113-53.rev.o1.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109365,bde7d947d1b2f2 X-Google-Attributes: gid109365,public X-Google-Thread: 104de1,bde7d947d1b2f2 X-Google-Attributes: gid104de1,public X-Google-Thread: f6611,bde7d947d1b2f2 X-Google-Attributes: gidf6611,public X-Google-Thread: 11301e,bde7d947d1b2f2 X-Google-Attributes: gid11301e,public X-Google-ArrivalTime: 2003-08-31 21:12:50 PST From: "Uri Dimant" <urid@iscar.co.il> References: <l.1062386880.1390777587@host-66-81-113-53.rev.o1.com> Subject: Re: subsum Date: Mon, 1 Sep 2003 07:10:35 +0200 Lines: 72 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: <OzK3o8DcDHA.1744@TK2MSFTNGP12.phx.gbl> Newsgroups: bit.databases.mssql-l,comp.databases.ms-sqlserver,microsoft.public.sqlserver.mseq,microsoft.public.sqlserver.programming NNTP-Posting-Host: bzq-25-106-78.cust.bezeqint.net 212.25.106.78 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!msrtrans1!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl