Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Unanswered: I need help with a CAST() problem

    I have been working on this problem for my DB class for a few hours now and I can't seem to wrap my head around it.

    I am working with a table MOVIES(MovieID, Title, ReleaseYear, Rating, RunningTime) and I need to figure out a way to group them according to the half hour they fall into. For example, if the running time of Movie1 is 65 minutes, it should fall into a category named 60. If it is 82 minutes long, then it should fall into the 90 minutes category. Similarly, if it is 14 minutes long, it should fall into a category of 0 minutes.

    I know there is a way to do this with the cast function but I can't seem to figure it out.

    Thank you very much for your help.

  2. #2
    Join Date
    Oct 2011
    Posts
    2
    *SOLVED*

    If anyone was curious, I managed to get the results I wanted with the following code:

    Code:
    select HalfHourBlock, count(*) as HowMany
    from
    (select 30*cast((10*cast(runningtime/10 as int))/30 as int) as HalfHourBlock, 30*cast((10*cast(runningtime/10 as int))/30 as int) as HowMany
    from sciore.movie)
    group by HalfHourBlock
    order by HalfHourBlock

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •