Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Averaging in SQL

Author  Topic 

qwerty1234
Starting Member

13 Posts

Posted - 2011-12-09 : 12:24:41
Hello there,

I have created a database for a DVD company. For a report section I have created a view which I plan to then bring up in the CMD window. What I am wanting to do is, provide an average of how many Rentals a Member has taken out, say in a month or a week whichever would be simpler. The problem I'm having is actually averaging this, I thought about averaging the number of dates but I'm having trouble implementing it. Any ideas?

Here is my code so far:
/*View*/
CREATE VIEW testing AS
SELECT M.memberID, R.rentalID, R.r_dateout
FROM testrental2 R
LEFT JOIN testmember2 M

/*Formatting and Computes etc*/
SPOOL TEMP
CLEAR COLUMNS
CLEAR BREAKS
CLEAR COMPUTES

COLUMN rentalID HEADING 'RENTAL ID'
COLUMN memberID HEADING 'MEMBER ID'
COLUMN r_dateout HEADING 'DATE OF RENTAL'

BREAK ON rentalID SKIP 1 ON REPORT
COMPUTE COUNT OF memberID ON REPORT
COMPUTE COUNT OF rentalID ON REPORT

SET PAGESIZE 24
SET NEWPAGE 0
SET LINESIZE 50
TTITLE CENTER 'R E N T A L T R A C K E R' SKIP 2 -
LEFT 'REPORT' RIGHT 'PAGE:' -
FORMAT 999 SQL.PNO SKIP 2
BTITLE CENTER 'FLIX CONFIDENTIAL'

SELECT *
FROM testing;

SPOOL OFF

DROP VIEW testing;

Thank you in advance!

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-12-09 : 13:00:56
Might try posting this on an Oracle forum, as this forum specialized on MS SQL Server.
Go to Top of Page
   

- Advertisement -