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

    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 Offline
    S Offline
    Serguei
    wrote on last edited by
    #39

    SELECT Region, Contact
    FROM Fig1
    ORDER BY
    CASE Region WHEN 'Durban' THEN 1 ELSE 2 END,
    Contact

    Tip, you can do:

    SELECT TOP 100 PERCENT * FROM Fig1

    Even better tip: Don't do that - your query doesn't guarantee (although will more than likely result in) the correct ordering. You should have sorted by outerSeq, Contact in the outer query. See http://blogs.msdn.com/b/queryoptteam/archive/2006/03/24/560396.aspx

    B 1 Reply Last reply
    0
    • S Slacker007

      SELECT * FROM YourTable ORDERBY Durban, Johannesburg, CapeTown INTHATORDER

      M Offline
      M Offline
      Michael Kingsford Gray
      wrote on last edited by
      #40

      Won't work. The middle "Cape Town" has the blank missing, and is "CapeTown" This makes it a very hard problem.

      1 Reply Last reply
      0
      • S Serguei

        SELECT Region, Contact
        FROM Fig1
        ORDER BY
        CASE Region WHEN 'Durban' THEN 1 ELSE 2 END,
        Contact

        Tip, you can do:

        SELECT TOP 100 PERCENT * FROM Fig1

        Even better tip: Don't do that - your query doesn't guarantee (although will more than likely result in) the correct ordering. You should have sorted by outerSeq, Contact in the outer query. See http://blogs.msdn.com/b/queryoptteam/archive/2006/03/24/560396.aspx

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

        Thanks, I especially like the top 100 percent

        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
          altncsab
          wrote on last edited by
          #42

          This is my solution. Because there was no pre-condition then anything is allowed :-D

          declare @T_MyTable Table(Region varchar(200), Contact varchar(200))

          select case when Contact = 'Fred' and Region like 'Cape%Town' then 'CapeTown'
          when Region like 'Cape%Town' then 'Cape Town'
          else Region end Region,
          Contact
          from @T_MyTable
          order by substring(Region,2,1) desc, Contact

          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
            Simon_Duckett
            wrote on last edited by
            #43

            SELECT [Region], [Contact] FROM Table1 ORDER BY SUBSTRING(REVERSE([Region]), 2, 1), [Contact]

            J 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
              KP Lee
              wrote on last edited by
              #44

              This doesn't look like a question geared to testing your SQL skills, but your skill at defining "real" requirements from something that seems very silly at first. 1. Assume the person asking this, isn't a lune escaped from the asylum. 2. Try to find the underlying order that they are requesting. 3. ASK them what the underlying order is, suggesting a possibility. 4 ASK them the schema information you need in order to write the query. Sort of like: I see these regions are all in South Africa. I'm not that informed about that area, are you ordering this query by population? No? What is the order criteria you are using? Then find out if the criteria is in the table you are querying? Or they could be testing your knowledge of DB design and waiting for you to ask why the H the region and the name are stored in the same table in the first place. Failing all that, just answer the question. There are a bunch of ways to do it. You can throw in a case statement in a batch select and select the two fields and order by the case result, the union all solution would work, creating a temp table and joining with it is a third option.

              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

                J Offline
                J Offline
                James H
                wrote on last edited by
                #45

                SELECT Region, Contact FROM RegionTable ORDER BY SubString(Region,2,1) DESC, Contact ASC

                1 Reply Last reply
                0
                • S Simon_Duckett

                  SELECT [Region], [Contact] FROM Table1 ORDER BY SUBSTRING(REVERSE([Region]), 2, 1), [Contact]

                  J Offline
                  J Offline
                  James H
                  wrote on last edited by
                  #46

                  Ha - you beat me

                  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
                    Mark_Wallace
                    wrote on last edited by
                    #47

                    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 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
                      #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
                                          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