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
 View: incl Average & Group By

Author  Topic 

cathymomo
Starting Member

10 Posts

Posted - 2009-03-10 : 13:13:56
Hi, just wondering if this looks correct as I do not have access to SQL Server right now.

Table:
create table ExpenseItem(
EINo integer not null IDENTITY,
ExpDesc varchar(255) not null,
ExpenseDate datetime DEFAULT GETDATE() not null,
ExpAmt money DEFAULT '0' not null,
ExpApprAmt money DEFAULT '0',
ERNo integer not null,
ECNo integer not null,
AssetNo integer,
CONSTRAINT ExpApprAmt CHECK (ExpApprAmt<=ExpAmt),
PRIMARY KEY (EINo),
FOREIGN KEY (ERNo) REFERENCES ExpenseReport ON DELETE CASCADE,
FOREIGN KEY (ECNo) REFERENCES ExpCat,
FOREIGN KEY (AssetNo) REFERENCES Asset ON DELETE SET NULL );

Question:
2. Create a view that groups each ExpDesc (Expense Descriptions) and the average Cost (ExpAmt).

My Solution:
CREATE VIEW ExpenseReport_View1 AS
SelecT ExpDesc, AVG(ExpAmt)
FROM ExpenseReport
GROUP BY ExpDesc


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-10 : 13:24:23
quote:
Originally posted by cathymomo

Hi, just wondering if this looks correct as I do not have access to SQL Server right now.

Table:
create table ExpenseItem(
EINo integer not null IDENTITY,
ExpDesc varchar(255) not null,
ExpenseDate datetime DEFAULT GETDATE() not null,
ExpAmt money DEFAULT '0' not null,
ExpApprAmt money DEFAULT '0',
ERNo integer not null,
ECNo integer not null,
AssetNo integer,
CONSTRAINT ExpApprAmt CHECK (ExpApprAmt<=ExpAmt),
PRIMARY KEY (EINo),
FOREIGN KEY (ERNo) REFERENCES ExpenseReport ON DELETE CASCADE,
FOREIGN KEY (ECNo) REFERENCES ExpCat,
FOREIGN KEY (AssetNo) REFERENCES Asset ON DELETE SET NULL );

Question:
2. Create a view that groups each ExpDesc (Expense Descriptions) and the average Cost (ExpAmt).

My Solution:
CREATE VIEW ExpenseReport_View1 AS
SelecT ExpDesc, AVG(ExpAmt)
FROM ExpenseReport ExpenseItem
GROUP BY ExpDesc





AS per posted data above, the table name used in view is wrong
Go to Top of Page
   

- Advertisement -