Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SQL statement that will perform a daily sum aggregation my last chance Expand / Collapse
Author
Message
Posted Wednesday, July 3, 2013 2:05 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, July 29, 2013 2:56 AM
Points: 16, Visits: 20
a SQL statement that will perform a daily sum aggregation on the field cost. It must only use costs that are associated with the follow items: Z001, Z002. The cost must also only come from division 1. Below is the example table that you will be retrieving data from:

Costs
• Receipt
• Date
• Item
• Reason
• Division
• Cost

I have tried this :

use STEVENTEST
go
CREATE FUNCTION Daily_Cost1
(

@item varchar , @Division nchar
)
RETURNS money
AS
BEGIN

DECLARE @daily_cost money
DECLARE @Cost_date date

set @Cost_date = GETDATE ()


if
@item = 'Z001' OR @item ='Z002'

SELECT @daily_cost = SUM(cost) from Cost

where @Cost_date =@Cost_date

RETURN @daily_cost

END
GO
Post #1469893
Posted Wednesday, July 3, 2013 3:23 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Sunday, October 19, 2014 2:53 AM
Points: 3,133, Visits: 3,402
Is this homework or a real life problem?

-------------------------------
Posting Data Etiquette - Jeff Moden
Smart way to ask a question

There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx
Post #1469934
Posted Wednesday, July 3, 2013 3:27 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, July 29, 2013 2:56 AM
Points: 16, Visits: 20
it's my test for BI position ,It's a real problem
Post #1469939
Posted Wednesday, July 3, 2013 5:38 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:54 AM
Points: 6,813, Visits: 14,028
engstevo (7/3/2013)
it's my test for BI position ,It's a real problem


It's SQL Server 101, and I'm surprised that the tests for a BI position can be this simple. If you cannot work at this level of simplicity, then you may wish to consider studying for a little longer before applying again. Real world BI problems and their solutions are unlikely to be within your capabilities at this time.


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1470003
Posted Wednesday, July 3, 2013 8:50 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, October 3, 2014 9:25 AM
Points: 895, Visits: 2,432
Is this a test that you are setting up?

_________________________________________________________________________
SSC Guide to Posting and Best Practices
Post #1470093
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse