• DKN2101 (4/24/2013)


    I have a table called DollarTransactions in a database, which records purchases. The table has the following fields, which you can see by clicking the link to a screenshot:

    I need to write 3 queries using these fields:

    1) Total Cents for each day in the month of March 2013. Revenue is measured with the "cents" field.

    2) Total Cents per hour for each day in March 2013

    3) User ID of the user who spent the most Cents in December 2012?

    I was working on a query for #1 that went like this:

    SELECT trunc(createdDate, 'HH') "Hour", sum(cents)

    FROM DollarTransactions

    WHERE createdDate BETWEEN '2013-03-01' AND '2013-03-31'

    GROUP BY trunc(createdDate, 'HH')

    But I don't know if that's right, and I'm lost on the other queries. Any help would be really appreciated!

    This looks suspiciously like homework. It also is Oracle syntax, not sql server.

    We will help guide you with homework but not give you the answers. What have you tried so far?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/