Article View: comp.databases.ms-sqlserver
Article #104Re: sql question
From: BP Margolin
Date: Sun, 13 May 2001 19:41
Date: Sun, 13 May 2001 19:41
75 lines
3749 bytes
3749 bytes
create table squibbe
(
AccountNum int,
OrderType char (1),
MonthDate varchar (12)
)
go
insert into squibbe values (1, 'A', 'April')
insert into squibbe values (1, 'B', 'May')
insert into squibbe values (1, 'B', 'May')
insert into squibbe values (2, 'B', 'April')
insert into squibbe values (2, 'B', 'May')
insert into squibbe values (2, 'C', 'May')
insert into squibbe values (3, 'C', 'May')
select AccountNum as account,
sum(case when OrderType = 'A' then 1 else 0 end) as TotA,
sum(case when OrderType = 'B' then 1 else 0 end) as TotB,
sum(case when OrderType = 'C' then 1 else 0 end) as TotC,
count(*)
from squibbe
where MonthDate = 'May'
group by AccountNum
order by AccountNum
-------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which
can be cut and pasted into Query Analyzer is appreciated.
<u95886230@spawnkill.ip-mobilphone.net> wrote in message
news:l.989779505.1960693359@[212.171.170.132]...
> Please help, I am trying to write an SQL statement but with no success as
I am just
> starting out with sql.
>
> I have a table with 3 columns: Account# ,OrderType and date
> example of data:
> Account# ¦ Ordertype ¦ Date
> 1 ¦ A ¦ April
> 1 ¦ B ¦ May
> 1 ¦ B ¦ May
> 2 ¦ B ¦ April
> 2 ¦ B ¦ May
> 2 ¦ C ¦ May
> 3 ¦ C ¦ May
>
>
> I need to write a select that will show me the totals of EACH type for
EACH account AND
> total ordersplaced for a SPECIFIC month eg..Show me the results for May...
>
> account ¦ TotA ¦ TotB ¦ TotC ¦ Total
> 1 ¦ 0 ¦ 2 ¦ 0 ¦ 2
> 2 ¦ 0 ¦ 1 ¦ 1 ¦ 2
> 3 ¦ 0 ¦ 0 ¦ 1 ¦ 1
>
> I can use temp tables, but need a solution written as basic as pssible so
I can understand
> it (all in the form select this from that)
> any help would be fantastic as I am completely stuck and have been trying
for about a week
>
> thanks
> sgebbie@ciaoweb.it
>
>
>
>
> --
> Sent by sgebbie from ciaoweb piece from it
> 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:
<3afee1b8_4@news3.prserv.net>Path:
arc1-ca.pugleaf.net!archiver1.sj.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.us.prserv.net!prserv.net!news3.prserv.net!32.101.37.74References:
<l.989779505.1960693359@[212.171.170.132]>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: ff490,5eea0abcbcb86736 X-Google-Attributes: gidff490,public X-Google-Thread: 104de1,b1745e9b0ae2e79d X-Google-Attributes: gid104de1,public X-Google-ArrivalTime: 2001-05-13 12:37:09 PST Reply-To: "BP Margolin" <bpmargo@attglobal.net> From: "BP Margolin" <bpmargo@attglobal.net> Newsgroups: comp.databases.ms-sqlserver,cz.comp.microsoft.sql References: <l.989779505.1960693359@[212.171.170.132]> Subject: Re: sql question Date: Sun, 13 May 2001 15:41:20 -0400 Lines: 77 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 32.101.37.74 Message-ID: <3afee1b8_4@news3.prserv.net> X-Trace: 13 May 2001 19:34:16 GMT, 32.101.37.74 Organization: Global Network Services - Remote Access Mail & News Services X-Complaints-To: abuse@prserv.net Path: arc1-ca.pugleaf.net!archiver1.sj.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.us.prserv.net!prserv.net!news3.prserv.net!32.101.37.74