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. The Lounge
  3. Job Application Test from Hell

Job Application Test from Hell

Scheduled Pinned Locked Moved The Lounge
databasequestioncareer
64 Posts 33 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.
  • B Brady Kelly

    I'm not looking for an answer here, I found my own, but this is quite a hard question. Given the table from Fig.1, write an SQL Select statement that would re-organize the results to look like Fig.2 Fig. 1

    Region

    Contact

    Cape Town

    Fred

    CapeTown

    Joe

    Cape Town

    Anna

    Durban

    John

    Durban

    Mary

    Johannesburg

    Frank

    Fig. 2

    Region

    Contact

    Durban

    John

    Durban

    Mary

    Johannesburg

    Frank

    Cape Town

    Anna

    CapeTown

    Fred

    Cape Town

    Joe

    C Offline
    C Offline
    Chris Meech
    wrote on last edited by
    #5

    You're just like my users, you expect me to divine the requirements.

    Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

    C 1 Reply Last reply
    0
    • B Brady Kelly

      I'm not looking for an answer here, I found my own, but this is quite a hard question. Given the table from Fig.1, write an SQL Select statement that would re-organize the results to look like Fig.2 Fig. 1

      Region

      Contact

      Cape Town

      Fred

      CapeTown

      Joe

      Cape Town

      Anna

      Durban

      John

      Durban

      Mary

      Johannesburg

      Frank

      Fig. 2

      Region

      Contact

      Durban

      John

      Durban

      Mary

      Johannesburg

      Frank

      Cape Town

      Anna

      CapeTown

      Fred

      Cape Town

      Joe

      S Offline
      S Offline
      Slacker007
      wrote on last edited by
      #6

      SELECT * FROM YourTable ORDERBY Durban, Johannesburg, CapeTown INTHATORDER

      M 1 Reply Last reply
      0
      • C Chris Meech

        You're just like my users, you expect me to divine the requirements.

        Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #7

        Yeah, I expect that's the main thing he was to glean from the question.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        P T 2 Replies Last reply
        0
        • B Brady Kelly

          I'm not looking for an answer here, I found my own, but this is quite a hard question. Given the table from Fig.1, write an SQL Select statement that would re-organize the results to look like Fig.2 Fig. 1

          Region

          Contact

          Cape Town

          Fred

          CapeTown

          Joe

          Cape Town

          Anna

          Durban

          John

          Durban

          Mary

          Johannesburg

          Frank

          Fig. 2

          Region

          Contact

          Durban

          John

          Durban

          Mary

          Johannesburg

          Frank

          Cape Town

          Anna

          CapeTown

          Fred

          Cape Town

          Joe

          R Offline
          R Offline
          realJSOP
          wrote on last edited by
          #8

          First, the data input routine allowed unvalidated data (the "CapeTown" entry). Second, it's apparently only ordered by region, and the name column doesn't have any brearing. In essense, you should have punched the interviewer in the mouth for wasting your time.

          .45 ACP - because shooting twice is just silly
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

          B 1 Reply Last reply
          0
          • C Christian Graus

            Is there any sense to that order ?

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            B Offline
            B Offline
            Brady Kelly
            wrote on last edited by
            #9

            Only in that there is a horizontal partitioning, i.e. rows >= Durban versus rows < Durban, and an apparent outer ordering by partition.

            1 Reply Last reply
            0
            • S Single Step Debugger

              Brady Kelly wrote:

              but this is quite a hard question

              You are sarcastic right? "Union All" will do the job pretty easy.

              The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

              B Offline
              B Offline
              Brady Kelly
              wrote on last edited by
              #10

              How do you ensure the required ordering?

              S 2 Replies Last reply
              0
              • C Christian Graus

                Is there any sense to that order ?

                Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                W Offline
                W Offline
                wolfbinary
                wrote on last edited by
                #11

                I was thinking the same thing.

                That's called seagull management (or sometimes pigeon management)... Fly in, flap your arms and squawk a lot, crap all over everything and fly out again... by _Damian S_

                1 Reply Last reply
                0
                • R realJSOP

                  First, the data input routine allowed unvalidated data (the "CapeTown" entry). Second, it's apparently only ordered by region, and the name column doesn't have any brearing. In essense, you should have punched the interviewer in the mouth for wasting your time.

                  .45 ACP - because shooting twice is just silly
                  -----
                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                  B Offline
                  B Offline
                  Brady Kelly
                  wrote on last edited by
                  #12

                  It was by email, and solvable. Durban and Cape Town contacts are sorted by name in the requirement. All contacts are sorted only by Region in the input data.

                  C 1 Reply Last reply
                  0
                  • B Brady Kelly

                    I'm not looking for an answer here, I found my own, but this is quite a hard question. Given the table from Fig.1, write an SQL Select statement that would re-organize the results to look like Fig.2 Fig. 1

                    Region

                    Contact

                    Cape Town

                    Fred

                    CapeTown

                    Joe

                    Cape Town

                    Anna

                    Durban

                    John

                    Durban

                    Mary

                    Johannesburg

                    Frank

                    Fig. 2

                    Region

                    Contact

                    Durban

                    John

                    Durban

                    Mary

                    Johannesburg

                    Frank

                    Cape Town

                    Anna

                    CapeTown

                    Fred

                    Cape Town

                    Joe

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #13

                    The correct answer is: "With which database system?" P.S. With Access/Jet via ADO.net:

                    select * from RegionContact order by len(Region) mod 2,Region,Contact

                    Region Contact


                    Durban John
                    Durban Mary
                    Johannesburg Frank
                    Cape Town Anna
                    Cape Town Fred
                    Cape Town Joe

                    6 records affected.

                    modified on Wednesday, November 24, 2010 4:03 PM

                    A 1 Reply Last reply
                    0
                    • B Brady Kelly

                      I'm not looking for an answer here, I found my own, but this is quite a hard question. Given the table from Fig.1, write an SQL Select statement that would re-organize the results to look like Fig.2 Fig. 1

                      Region

                      Contact

                      Cape Town

                      Fred

                      CapeTown

                      Joe

                      Cape Town

                      Anna

                      Durban

                      John

                      Durban

                      Mary

                      Johannesburg

                      Frank

                      Fig. 2

                      Region

                      Contact

                      Durban

                      John

                      Durban

                      Mary

                      Johannesburg

                      Frank

                      Cape Town

                      Anna

                      CapeTown

                      Fred

                      Cape Town

                      Joe

                      A Offline
                      A Offline
                      AspDotNetDev
                      wrote on last edited by
                      #14

                      So here's my guess as to what the sort order is:

                      • Sort by region, ascending, but making the first item group (by region) in that sort the last item. Do not consider whitespace in the sort order.
                      • When two or more of the regions are the same (again, excluding whitespace), sort by contact ascending.

                      Rather than follow those zany rules, I'd probably just do this:

                      SELECT 'Durban' AS Region, 'John' AS Contact
                      UNION
                      SELECT 'Durban', 'Mary'
                      UNION
                      SELECT 'Johannesburg', 'Frank'
                      UNION
                      SELECT 'Cape Town', 'Anna'
                      UNION
                      SELECT 'CapeTown', 'Fred'
                      UNION
                      SELECT 'Cape Town', 'Joe'

                      [Forum Guidelines]

                      1 Reply Last reply
                      0
                      • B Brady Kelly

                        I'm not looking for an answer here, I found my own, but this is quite a hard question. Given the table from Fig.1, write an SQL Select statement that would re-organize the results to look like Fig.2 Fig. 1

                        Region

                        Contact

                        Cape Town

                        Fred

                        CapeTown

                        Joe

                        Cape Town

                        Anna

                        Durban

                        John

                        Durban

                        Mary

                        Johannesburg

                        Frank

                        Fig. 2

                        Region

                        Contact

                        Durban

                        John

                        Durban

                        Mary

                        Johannesburg

                        Frank

                        Cape Town

                        Anna

                        CapeTown

                        Fred

                        Cape Town

                        Joe

                        A Offline
                        A Offline
                        Andy Brummer
                        wrote on last edited by
                        #15

                        I hope the question was an attempt to see if you would back away from the keyboard and start asking questions. If not, they deserve all the gung ho developers that they get.

                        Curvature of the Mind

                        1 Reply Last reply
                        0
                        • B Brady Kelly

                          How do you ensure the required ordering?

                          S Offline
                          S Offline
                          Single Step Debugger
                          wrote on last edited by
                          #16

                          We can’t use “order by” with the union but we could unite every single row separately – ugly but works.

                          The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                          1 Reply Last reply
                          0
                          • B Brady Kelly

                            How do you ensure the required ordering?

                            S Offline
                            S Offline
                            Single Step Debugger
                            wrote on last edited by
                            #17

                            select * from (select * from dbo.RegionTable RT
                            where RT.Region = 'Durban' order by RT.Contact asc) as union1
                            union all
                            select * from (select * from dbo.RegionTable RT
                            where RT.Region = 'Johannesburg' order by RT.Contact asc) as union3
                            union all
                            select * from (select * from dbo.RegionTable RT
                            where RT.Region = 'Cape Town' order by RT.Contact asc) as union2

                            The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                            C B 2 Replies Last reply
                            0
                            • S Single Step Debugger

                              select * from (select * from dbo.RegionTable RT
                              where RT.Region = 'Durban' order by RT.Contact asc) as union1
                              union all
                              select * from (select * from dbo.RegionTable RT
                              where RT.Region = 'Johannesburg' order by RT.Contact asc) as union3
                              union all
                              select * from (select * from dbo.RegionTable RT
                              where RT.Region = 'Cape Town' order by RT.Contact asc) as union2

                              The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                              C Offline
                              C Offline
                              Chris Meech
                              wrote on last edited by
                              #18

                              This will fail, since one of the regions has been entered as "CapeTown" instead of "Cape Town". :)

                              Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

                              S 1 Reply Last reply
                              0
                              • B Brady Kelly

                                I'm not looking for an answer here, I found my own, but this is quite a hard question. Given the table from Fig.1, write an SQL Select statement that would re-organize the results to look like Fig.2 Fig. 1

                                Region

                                Contact

                                Cape Town

                                Fred

                                CapeTown

                                Joe

                                Cape Town

                                Anna

                                Durban

                                John

                                Durban

                                Mary

                                Johannesburg

                                Frank

                                Fig. 2

                                Region

                                Contact

                                Durban

                                John

                                Durban

                                Mary

                                Johannesburg

                                Frank

                                Cape Town

                                Anna

                                CapeTown

                                Fred

                                Cape Town

                                Joe

                                C Offline
                                C Offline
                                Chris Meech
                                wrote on last edited by
                                #19

                                The only obvious ordering sequence is the number of capitalized letters in Region, followed by the Region, followed by the Contact. :)

                                Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

                                P 1 Reply Last reply
                                0
                                • B Brady Kelly

                                  It was by email, and solvable. Durban and Cape Town contacts are sorted by name in the requirement. All contacts are sorted only by Region in the input data.

                                  C Offline
                                  C Offline
                                  Christian Graus
                                  wrote on last edited by
                                  #20

                                  OK, so it's sorted by two fields we can't see ( region and email address ) ?

                                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                                  G 1 Reply Last reply
                                  0
                                  • B Brady Kelly

                                    I'm not looking for an answer here, I found my own, but this is quite a hard question. Given the table from Fig.1, write an SQL Select statement that would re-organize the results to look like Fig.2 Fig. 1

                                    Region

                                    Contact

                                    Cape Town

                                    Fred

                                    CapeTown

                                    Joe

                                    Cape Town

                                    Anna

                                    Durban

                                    John

                                    Durban

                                    Mary

                                    Johannesburg

                                    Frank

                                    Fig. 2

                                    Region

                                    Contact

                                    Durban

                                    John

                                    Durban

                                    Mary

                                    Johannesburg

                                    Frank

                                    Cape Town

                                    Anna

                                    CapeTown

                                    Fred

                                    Cape Town

                                    Joe

                                    T Offline
                                    T Offline
                                    Tomz_KV
                                    wrote on last edited by
                                    #21

                                    select region, contact from ( select region, contact, case when region='Johannesburg' then 5 when region='Durban' then 1 else 10 end as Expr1 from TableName ) as Tbl order by Expr1, Contact

                                    TOMZ_KV

                                    S 1 Reply Last reply
                                    0
                                    • C Chris Meech

                                      This will fail, since one of the regions has been entered as "CapeTown" instead of "Cape Town". :)

                                      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

                                      S Offline
                                      S Offline
                                      Single Step Debugger
                                      wrote on last edited by
                                      #22

                                      No it won’t because the missing interval is due to the level of Brady’s BAC rather than the original task conditions. :)

                                      The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                                      B 1 Reply Last reply
                                      0
                                      • S Single Step Debugger

                                        No it won’t because the missing interval is due to the level of Brady’s BAC rather than the original task conditions. :)

                                        The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                                        B Offline
                                        B Offline
                                        Brady Kelly
                                        wrote on last edited by
                                        #23

                                        Haha, no, I suspect it was a typo on their part, but I treated it like I would a landmine. :~

                                        P 1 Reply Last reply
                                        0
                                        • S Single Step Debugger

                                          select * from (select * from dbo.RegionTable RT
                                          where RT.Region = 'Durban' order by RT.Contact asc) as union1
                                          union all
                                          select * from (select * from dbo.RegionTable RT
                                          where RT.Region = 'Johannesburg' order by RT.Contact asc) as union3
                                          union all
                                          select * from (select * from dbo.RegionTable RT
                                          where RT.Region = 'Cape Town' order by RT.Contact asc) as union2

                                          The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                                          B Offline
                                          B Offline
                                          Brady Kelly
                                          wrote on last edited by
                                          #24

                                          The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified. :) Here is mine, a little more general but very much the same:

                                          select first.*, 0 outerSeq from (select top(select COUNT(*) from Contacts) * from Contacts where Region >= 'Durban' order by Region, Contact) first
                                          union all
                                          select second.*, 1 outerSeq from (select top (select COUNT(*) from Contacts) * from Contacts where Region < 'Durban' order by Region, Contact) as second
                                          order by outerSeq

                                          S 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