Tuesday, June 18, 2013

How to create derived Relation In MS Sqlserver

Sql Allows a subquery expression to be used in the from cluse. If we use such an expression then we must give the result relation a name, and we can rename the attributes, We do this renaming by useing the as clause. For example, consider the subquery....

 

select Employee1, qty from

(

select Employeeid ,AVG( SampleQty) from Table

group by EmployeeID

) as

 Result(Employee1, qty )

 

This subquery generates a relation consisting of the names of all employeeid and therir corresponding average sampleQty  . The subquery result is named result, with rhe attributes Employee1, qty.