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

    P Offline
    P Offline
    PhilLeTaxi
    wrote on last edited by
    #48

    Hi, With this request,

    SELECT region, contact FROM `localisation` ORDER BY SUBSTRING(region,2,2) DESC, contact ASC

    I obtain :

    region contact
    Durban John
    Durban Mary
    Johannesburg Frank
    Cape Town Anna
    Cape Town Fred
    CapeTown Joe

    The list is ordered regarding the second letter of the region. To avoid the missing blank in CapeTown, the end of the string is cut. Bye

    1 Reply Last reply
    0
    • M Mark_Wallace

      It's a ridiculous question. If there's a reason for ordering as in ex.2, then there must be data that allows the order in that or another table (area code, telephone dialing code, or whatever). If such data isn't available, then the correct answer to the question would be to add a column for it. Otherwise, if it's just an arbitrary order for existing data, use an arbitrary solution -- the second letter of each location in reverse alphabetical order, for example -- then stuff it up the questioner's @rse.

      I wanna be a eunuchs developer! Pass me a bread knife!

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

      It didn't strike me as that It's in order of Region, Contact asc, but it starts at the 2nd region, wrapping around to the first.

      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

        X Offline
        X Offline
        Xapp
        wrote on last edited by
        #50

        SELECT * FROM t ORDER BY SUBSTRING(REPLACE(Region, ' ', '') FROM 2) DESC, Contact ASC Tricky.

        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
          PhilLeTaxi
          wrote on last edited by
          #51

          Hi Again, Oups, I didn't see the response of James H. which has found the same solution. Sorry for the noise. Bye

          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

            N Offline
            N Offline
            Narud Shiro
            wrote on last edited by
            #52

            Guessing that we are using talking of SQL Server, and without using case when, union, or any other thing like them, this is my best: select Region, Contact from Contacts order by replace(Region, ' ', ''), Contact Can you give me a B+ at least, teacher?

            P 1 Reply Last reply
            0
            • N Narud Shiro

              Guessing that we are using talking of SQL Server, and without using case when, union, or any other thing like them, this is my best: select Region, Contact from Contacts order by replace(Region, ' ', ''), Contact Can you give me a B+ at least, teacher?

              P Offline
              P Offline
              PhilLeTaxi
              wrote on last edited by
              #53

              Hi, Your request gives this result :

              region contact
              Cape Town Anna
              Cape Town Fred
              CapeTown Joe
              Durban John
              Durban Mary
              Johannesburg Frank

              This is slightly different from the expected result. Bye

              1 Reply Last reply
              0
              • C Christian Graus

                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 Offline
                G Offline
                ghle
                wrote on last edited by
                #54

                Christian Graus wrote:

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

                I think he meant that the test was sent to him via e-mail, not that e-mail was a hidden field.:confused: Heck, I'd just order by the hidden Sequence field. :)

                Gary

                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

                  M Offline
                  M Offline
                  Member 96
                  wrote on last edited by
                  #55

                  A job application test that doesn't reflect a real world problem is an utter waste of time and whoever devised this should be kicked in the balls and repeatedly told to "get real".


                  “If you want to build a ship, don't drum up people together to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea” - Antoine de Saint-Exupery

                  B 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

                    K Offline
                    K Offline
                    Kirk Wood
                    wrote on last edited by
                    #56

                    SELECT 'look for different job' FROM 'places not full of self serving jerks who wish to prove their supposed superiority' Personally, my experience is that places that serve up such a test are full of jerks who think too highly of themselves. They find great pride in their ability to find questions few can answer, and probably can't produce anything worth having anyway. The number of people who think they are great far exceeds the number who really are great.

                    1 Reply Last reply
                    0
                    • M Member 96

                      A job application test that doesn't reflect a real world problem is an utter waste of time and whoever devised this should be kicked in the balls and repeatedly told to "get real".


                      “If you want to build a ship, don't drum up people together to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea” - Antoine de Saint-Exupery

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

                      Well, the one that did reflect a real world problem, probably the only one, was: Given a list of names, identify duplicate names as well as possible misspellings of the same name. I scrawled something about soundex in my answer. This was a written test taken after hours. I had nobody to raise issues with, but plenty of time to really think things through.

                      1 Reply Last reply
                      0
                      • C Christian Graus

                        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.

                        T Offline
                        T Offline
                        TraceyTiethoff
                        wrote on last edited by
                        #58

                        That's a good point Christian. My answer would be in the form of a question asked with the general idea of "What exactly are you trying to accomplish?". I can't imagine a reason for this sort order, as someone else mentioned. Either the order is insignificant, the significance is merely that some user likes it, or the data provided isn't complete and therefore doesn't reveal any logical reason for this order. I know programmers are often stuck with "just do it", but if the customer is open to it, I would prefer to have a discussion of the cost(both present and future) versus the benefit of having it this way (assuming it isn't an incomplete data issue).

                        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.

                          Z Offline
                          Z Offline
                          ZRonZ28
                          wrote on last edited by
                          #59

                          Fig. 2 Region Contact Durban John Durban Mary Johannesburg Frank Cape Town Anna CapeTown Fred Cape Town Joe The pattern seems pretty simple: 1. Region is reverse alphabetized using the second letter of the word (or maybe 2,3 and 4?), 2. Contact is alphabetized within the Region.

                          modified on Friday, November 26, 2010 10:50 AM

                          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

                            D Offline
                            D Offline
                            dada2010
                            wrote on last edited by
                            #60

                            Haha, i think i found the hidden order... Region are simply ordered by descending their longitude, contacts by the length of their name (descending) then by their fourth letter (ascending). As we know commonly longitudes of theses cities/regions are Cape Town : 18.45° Durban : 30.6° Johannesburg : 27° For the understanding, we suppose we have a table containing longitudes (while in real life we would need -of course- the request to connect to googlemap api to find it) (googlemap find CapeTown and Cape Town same longitude): wtf_region_longitude region longitude Cape Town 18 CapeTown 18 Durban 31 Johannesburg 27 and the table of fig 1: wtf_region_contacts Region Contact Cape Town Fred Cape Town Joe Cape Town Anna Durban John Durban Mary Johannesburg Frank Doing permutation between Joe and Fred, the request is :

                            select s.region, contact from
                            (
                            select c.region,
                            contact = case contact when 'Joe' then 'Fred' when 'Fred' then 'Joe' else contact end
                            ,contact as ocontact
                            from wtf_region_contacts c
                            ) s, wtf_region_longitude l
                            where s.region=l.region
                            order by longitude desc, LEN(contact) desc, SUBSTRING(contact,4,1) asc

                            --> region contact Durban John Durban Mary Johannesburg Frank Cape Town Anna CapeTown Fred Cape Town Joe Am I right ?

                            modified on Friday, November 26, 2010 4:30 AM

                            B 1 Reply Last reply
                            0
                            • D dada2010

                              Haha, i think i found the hidden order... Region are simply ordered by descending their longitude, contacts by the length of their name (descending) then by their fourth letter (ascending). As we know commonly longitudes of theses cities/regions are Cape Town : 18.45° Durban : 30.6° Johannesburg : 27° For the understanding, we suppose we have a table containing longitudes (while in real life we would need -of course- the request to connect to googlemap api to find it) (googlemap find CapeTown and Cape Town same longitude): wtf_region_longitude region longitude Cape Town 18 CapeTown 18 Durban 31 Johannesburg 27 and the table of fig 1: wtf_region_contacts Region Contact Cape Town Fred Cape Town Joe Cape Town Anna Durban John Durban Mary Johannesburg Frank Doing permutation between Joe and Fred, the request is :

                              select s.region, contact from
                              (
                              select c.region,
                              contact = case contact when 'Joe' then 'Fred' when 'Fred' then 'Joe' else contact end
                              ,contact as ocontact
                              from wtf_region_contacts c
                              ) s, wtf_region_longitude l
                              where s.region=l.region
                              order by longitude desc, LEN(contact) desc, SUBSTRING(contact,4,1) asc

                              --> region contact Durban John Durban Mary Johannesburg Frank Cape Town Anna CapeTown Fred Cape Town Joe Am I right ?

                              modified on Friday, November 26, 2010 4:30 AM

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

                              I think your scenario is actually more likely than the real pattern being sorting by the second char of region.

                              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
                                CodeNaked
                                wrote on last edited by
                                #62

                                Durban and Johannesburg are both divisible by 6.

                                SELECT * FROM Regions
                                ORDER BY
                                CASE LEN(Region) % 6
                                WHEN 0 THEN 0
                                ELSE ASCII(SUBSTRING(Contact,1,1)) END,
                                Region, Contact

                                Darwin

                                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

                                  N Offline
                                  N Offline
                                  narfnarf13206
                                  wrote on last edited by
                                  #63

                                  --There is no obvious sort in fig 2l; we have no specific req saying to order using a particular approach...so brute force order it. Obviously this solution wouldn't scale..then again any solution that makes an assumption that there is a scalable way to order it would only be correct by pure luck. Note - pseudocode, might have syntax errors but the basic methodology works select * from fig1 a into #temp01 --dump data into a temp table alter table #temp01 add orderr integer --add a new column update #temp01 set orderr = 1 where region = 'Durban' and Contact = 'John' --populate order info update #temp01 set orderr = 2 where region = 'Durban' and Contact = 'Mary' --populate order info --TODO update orderr for 4 remaining rows select region, contact from #temp01 order by orderr

                                  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

                                    R Offline
                                    R Offline
                                    redbones
                                    wrote on last edited by
                                    #64

                                    in oracle sql i could do select region, contact from select region, contact, decode(substr(region,1,1),'D',1,'J',2, 'C',3) ord from ) order by ord

                                    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