Click here to Skip to main content
15,892,059 members
Home / Discussions / Database
   

Database

 
GeneralRe: Simple Dataset Question... Pin
Verdant12322-Feb-04 3:01
Verdant12322-Feb-04 3:01 
GeneralParameters of PutElement() Pin
girl_lash18-Feb-04 16:26
girl_lash18-Feb-04 16:26 
Generalassociating child to parent Pin
ylaine18-Feb-04 16:05
ylaine18-Feb-04 16:05 
GeneralMissing VNSAPI32.dll Pin
Bakos, Zsolt18-Feb-04 9:50
Bakos, Zsolt18-Feb-04 9:50 
GeneralRe: Missing VNSAPI32.dll Pin
Mike Dimmick19-Feb-04 6:12
Mike Dimmick19-Feb-04 6:12 
GeneralTrouble with query Pin
gamerPotatoe18-Feb-04 1:38
gamerPotatoe18-Feb-04 1:38 
GeneralRe: Trouble with query Pin
Mike Dimmick18-Feb-04 2:36
Mike Dimmick18-Feb-04 2:36 
GeneralRe: Trouble with query Pin
Edbert P19-Feb-04 13:28
Edbert P19-Feb-04 13:28 
This is quite complex, but I'm gonna give it a try Smile | :)
You can probably do this in two ways (without using a temporary table, that is).

1. If you're fine with the result being shown vertically:

SELECT CLASS, DATENAME([month], RSRVDATE) AS Month, COUNT(*) AS Total<br />
FROM RESERVED_LEGS <br />
INNER JOIN Tickets_Purchased ON RESERVED_LEGS.PNR = Tickets_Purchased.TKTNO<br />
GROUP BY CLASS, MONTH(RSRVDATE)<br />
ORDER BY CLASS, MONTH(RSRVDATE)


This should return something like:
CLASS Month Total
First January 100
First February 150
...

2. If you want the result to be shown horizontally (this is more difficult):

SELECT CLASS, <br />
(SELECT COUNT(*) FROM RESERVED_LEGS INNER JOIN Tickets_Purchased AS TP ON RESERVED_LEGS.PNR = TP.TKTNO WHERE MONTH(RSRVDATE) = 1) AND TP.CLASS = TicketsPurchased.CLASS) AS Jan, <br />
(SELECT COUNT(*) FROM RESERVED_LEGS INNER JOIN Tickets_Purchased AS TP ON RESERVED_LEGS.PNR = TP.TKTNO WHERE MONTH(RSRVDATE) = 2) AND TP.CLASS = TicketsPurchased.CLASS) AS Feb,<br />
(SELECT COUNT(*) FROM RESERVED_LEGS INNER JOIN Tickets_Purchased AS TP ON RESERVED_LEGS.PNR = TP.TKTNO WHERE MONTH(RSRVDATE) = 3) AND TP.CLASS = TicketsPurchased.CLASS) AS Mar,<br />
...<br />
...<br />
...<br />
FROM Tickets_Purchased<br />
GROUP BY CLASS<br />
ORDER BY CLASS


You can always use the query from #1 and format it to present it the way you want it to be, as I think it will be the most efficient query from both.

I hope it helps Wink | ;)

PS: You might want to tweak the SQL queries a bit to make it work Smile | :)
PPS: Maybe there is a more efficient way to do #2. Anyone?

Edbert P.
Sydney, Australia.
GeneralHelp with big stored procedure Pin
Verdant12317-Feb-04 20:25
Verdant12317-Feb-04 20:25 
GeneralRe: Help with big stored procedure Pin
Not Active18-Feb-04 1:06
mentorNot Active18-Feb-04 1:06 
GeneralRe: Help with big stored procedure Pin
Verdant12318-Feb-04 1:58
Verdant12318-Feb-04 1:58 
Generalgetting columns data rowwise Pin
percyvimal17-Feb-04 16:59
percyvimal17-Feb-04 16:59 
GeneralRe: getting columns data rowwise Pin
Mazdak17-Feb-04 18:23
Mazdak17-Feb-04 18:23 
GeneralCreating SQL tables from XML schema Pin
blurp17-Feb-04 13:04
blurp17-Feb-04 13:04 
GeneralShowing Multiple tables in Datagrid Pin
Qamarwis17-Feb-04 9:56
Qamarwis17-Feb-04 9:56 
GeneralRe: uMultiple tables in Datagrid Pin
Mazdak17-Feb-04 10:01
Mazdak17-Feb-04 10:01 
QuestionWhat is ??? The Problem Pin
jinbabaj17-Feb-04 3:56
jinbabaj17-Feb-04 3:56 
AnswerRe: What is ??? The Problem Pin
Edbert P17-Feb-04 17:19
Edbert P17-Feb-04 17:19 
GeneralRetrieving a list of tables (ADO) Pin
pl0p16-Feb-04 17:28
pl0p16-Feb-04 17:28 
GeneralRe: Retrieving a list of tables (ADO) Pin
Mazdak16-Feb-04 17:47
Mazdak16-Feb-04 17:47 
GeneralRe: Retrieving a list of tables (ADO) Pin
-Dr_X-20-Feb-04 11:16
-Dr_X-20-Feb-04 11:16 
GeneralAccess Pin
Anonymous16-Feb-04 16:05
Anonymous16-Feb-04 16:05 
GeneralRe: Access Pin
-Dr_X-20-Feb-04 11:23
-Dr_X-20-Feb-04 11:23 
GeneralSelect MID?? instead of TOP Pin
krisp16-Feb-04 11:26
krisp16-Feb-04 11:26 
GeneralRe: Select MID?? instead of TOP Pin
John Kuhn16-Feb-04 11:46
John Kuhn16-Feb-04 11:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.