0

I have the following requirement-

1. Get the A_MINUTES column value from TableA for all rows 
2. Sum the A_MINUTES. 
3. Convert the summed minutes values to hours - divide by 60 
4. Round off the final hours value to 2 decimal places.

This needs to be written in SQL.

Do you think this query will have any rounding errors?

SELECT ROUND ( (SUM(A_MINUTES)/60.0) , 2) FROM TABLEA
Johannes Pille
  • 4,073
  • 4
  • 26
  • 27
user656523
  • 3,171
  • 3
  • 22
  • 19
  • 1
    the sql matches what your verbiage describes. – Randy May 02 '12 at 15:25
  • Is this homework? If so that is ok, it's a courtesy here to note your questions as such. People may give you more "academic" answers or try to help you learn more on homework questions. – Matthew May 02 '12 at 15:42
  • Please define 'rounding errors'. I'd imagine most major RDBMSs perform accurately enough for business purposes... – Clockwork-Muse May 02 '12 at 15:42

1 Answers1

1

Will it have any rounding errors?

That depends on what rounding scheme you want to implement.
The SQL code you posted will accomplish your goal but the default rounding scheme in SQL is not bankers rounding like the default scheme in .NET

http://msdn.microsoft.com/en-us/library/ms175003.aspx

Here is a good brief on different rounding method implementations in SQL:
http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/sql-server-rounding-methods

If you wanted to implement a banker's rounding scheme (like the default in .NET) then there are a few options. Here is a good discussion on the topic (it is for Oracle, but should applicable)
http://www.orafaq.com/forum/t/122001/2/

Matthew
  • 10,244
  • 5
  • 49
  • 104