Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. command implement loop

command implement loop

Scheduled Pinned Locked Moved Database
databaseoraclehelptutorial
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrkeivan
    wrote on last edited by
    #1

    Hey guys I have two tables 1- Holds the cars passed (CarId, DeviceId, PassDate) 2- Holds the List of Cameras capturing each car (DeviceID, DeviceName) I want to check on a specific Date the maximum number of car passed in period(every 60 minutes, 2 hours …) So I have to use a double loop the first for each device and the second for the period.

    For(everydevice)
    {
    For(every period in the time)
    }

    The should look like this List

    Device Name --------- Max Passed Cars

    Since I’m new to oracle SQL Programming I dunno how to implement this, I appreciate it if you can help me out

    C J 2 Replies Last reply
    0
    • M mrkeivan

      Hey guys I have two tables 1- Holds the cars passed (CarId, DeviceId, PassDate) 2- Holds the List of Cameras capturing each car (DeviceID, DeviceName) I want to check on a specific Date the maximum number of car passed in period(every 60 minutes, 2 hours …) So I have to use a double loop the first for each device and the second for the period.

      For(everydevice)
      {
      For(every period in the time)
      }

      The should look like this List

      Device Name --------- Max Passed Cars

      Since I’m new to oracle SQL Programming I dunno how to implement this, I appreciate it if you can help me out

      C Offline
      C Offline
      Chris Quinn
      wrote on last edited by
      #2

      You can do this in a single select query, grouping by deviceID, calculating Count(carId) with a where clause on the passdate between period start and period end

      ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

      M Richard Andrew x64R 2 Replies Last reply
      0
      • C Chris Quinn

        You can do this in a single select query, grouping by deviceID, calculating Count(carId) with a where clause on the passdate between period start and period end

        ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

        M Offline
        M Offline
        mrkeivan
        wrote on last edited by
        #3

        If i'm not mistaken this works when I want to get the maximum number, but here I want to see for example what is the maximum passed number of cars in every 60 minutes.

        C 1 Reply Last reply
        0
        • M mrkeivan

          If i'm not mistaken this works when I want to get the maximum number, but here I want to see for example what is the maximum passed number of cars in every 60 minutes.

          C Offline
          C Offline
          Chris Quinn
          wrote on last edited by
          #4

          You can also add a grouping on the DatePassed column, formatted in such a way as to just display the date and hour

          ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

          1 Reply Last reply
          0
          • M mrkeivan

            Hey guys I have two tables 1- Holds the cars passed (CarId, DeviceId, PassDate) 2- Holds the List of Cameras capturing each car (DeviceID, DeviceName) I want to check on a specific Date the maximum number of car passed in period(every 60 minutes, 2 hours …) So I have to use a double loop the first for each device and the second for the period.

            For(everydevice)
            {
            For(every period in the time)
            }

            The should look like this List

            Device Name --------- Max Passed Cars

            Since I’m new to oracle SQL Programming I dunno how to implement this, I appreciate it if you can help me out

            J Offline
            J Offline
            Jorgen Andersson
            wrote on last edited by
            #5

            I wish everyone was as clear in what they want.

            WITH CTE AS (
            SELECT CarId
            ,TO_CHAR(PassDate, 'YYYY-MM-DD HH24') AS hours
            ,TRUNC(PassDate, 'HH24') AS hours
            ,DeviceName
            FROM cars c,devices d
            WHERE c.DeviceID = d.DeviceID
            )
            SELECT Count(carID) Cars_passed
            ,hours
            ,devicename
            FROM CTE
            GROUP BY hourly
            ,devicename

            <edit>Revisited and fixed so that hours remains the correct type</edit>

            Wrong is evil and must be defeated. - Jeff Ello[^]

            M 1 Reply Last reply
            0
            • C Chris Quinn

              You can do this in a single select query, grouping by deviceID, calculating Count(carId) with a where clause on the passdate between period start and period end

              ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

              Richard Andrew x64R Offline
              Richard Andrew x64R Offline
              Richard Andrew x64
              wrote on last edited by
              #6

              Chris Quinn wrote:

              I'm an optoholic

              Actually, you mean optiholic because optimist is spelled with an 'i', not an 'o'. ;)

              The difficult we do right away... ...the impossible takes slightly longer.

              C 1 Reply Last reply
              0
              • Richard Andrew x64R Richard Andrew x64

                Chris Quinn wrote:

                I'm an optoholic

                Actually, you mean optiholic because optimist is spelled with an 'i', not an 'o'. ;)

                The difficult we do right away... ...the impossible takes slightly longer.

                C Offline
                C Offline
                Chris Quinn
                wrote on last edited by
                #7

                ... but alcoholic is spelt with an o, not an i!

                ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

                Richard Andrew x64R 1 Reply Last reply
                0
                • C Chris Quinn

                  ... but alcoholic is spelt with an o, not an i!

                  ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

                  Richard Andrew x64R Offline
                  Richard Andrew x64R Offline
                  Richard Andrew x64
                  wrote on last edited by
                  #8

                  Touche!

                  The difficult we do right away... ...the impossible takes slightly longer.

                  1 Reply Last reply
                  0
                  • J Jorgen Andersson

                    I wish everyone was as clear in what they want.

                    WITH CTE AS (
                    SELECT CarId
                    ,TO_CHAR(PassDate, 'YYYY-MM-DD HH24') AS hours
                    ,TRUNC(PassDate, 'HH24') AS hours
                    ,DeviceName
                    FROM cars c,devices d
                    WHERE c.DeviceID = d.DeviceID
                    )
                    SELECT Count(carID) Cars_passed
                    ,hours
                    ,devicename
                    FROM CTE
                    GROUP BY hourly
                    ,devicename

                    <edit>Revisited and fixed so that hours remains the correct type</edit>

                    Wrong is evil and must be defeated. - Jeff Ello[^]

                    M Offline
                    M Offline
                    mrkeivan
                    wrote on last edited by
                    #9

                    Thanx. ;-)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups