Exercises in t-SQL

  • capnhector (11/30/2012)


    ScottPletcher (11/30/2012)


    Eugene Elutin (11/30/2012)


    ScottPletcher (11/30/2012)


    ...

    In the interests of being thorough, I added a Message to my proposed solution back to them:

    SELECT

    ...as above...,

    CASE WHEN COUNT(*) > 3 THEN 'ERROR: > 3 TESTS FOUND, MID SCORE INACCURATE!' ELSE '' END AS Message

    To me, this teaches the students something important as well:

    Just because someone promises you there are only 3 values -- pinkie swear, cross their heart -- don't necessarily believe them! Either verify it 100%, or, if it's easy, add something to catch the unexpected. My sample table of data would of course have one student_id that had 4 test results and a middle value of 105 🙂 .

    That is I guess quintessence of the difference between "school" and "practice".

    Because, I would most definitely not add this check in my code!

    If someone would tell me that table should allow "only 3 values", instead of worrying about possibility of having data inconsistent at every query, I would enforce it by trigger or a constraint on computed column...

    Also, I kind of agree with Jeff on restrictions such as "single query" and "using basic sql". I would really want to see the best possible solution with showing knowledge of the most advanced SQL features instead of ability to solve irrelevant puzzles (aka SELECT EXP($) ;-)).

    If they can't solve this query without three CTEs and two table joins, that's not irrelevant to me. What better solution do you propose here with more advanced SQL?

    If they refuse to use only basic SQL for a query when I ask them to, that's not irrelevant to me either: it tells me things (good and bad).

    This will work even if you throw in a curve of 4 scores it will take the 3 earliest scores of course it uses some advanced sql (ROW_NUMBER() and PIVOT)

    declare @Test_Scores table ( student_id int, date_taken datetime, score decimal(4, 1))

    insert @Test_Scores

    select 1,GETDATE(),93

    union select 1,GETDATE() + 1,85

    union select 2,GETDATE(),88

    union select 2,GETDATE() + 1,64

    union select 2,GETDATE() + 2,99

    union select 3,GETDATE(),87

    SELECT student_id, [1],[2],[3]

    FROM (SELECT ROW_NUMBER() OVER (PARTITION BY student_id ORDER BY date_taken) rn, student_id, score

    FROM @Test_Scores)p

    PIVOT

    (MAX(Score) FOR rn IN ([1],[2],[3]))pvt

    That's not a valid solution: the tests are not hi, mid and low, in that order (should be ORDER BY score DESC).

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Eugene Elutin (11/30/2012)


    ... and got some pretty mediocre answers from (supposedly) experienced and skilled T-SQLers.

    I am not be surprised when good skilled T-SQLers come up with stupid answers on paper during interviews. I do prefer take them over to PC with SSMS...

    Anyway, I'm happy if you will rate myself here 🙂 :

    declare @Test_Scores table ( student_id int, date_taken datetime, score decimal(4, 1))

    insert @Test_Scores

    select 1,GETDATE(),93

    union select 1,GETDATE(),85

    union select 2,GETDATE(),88

    union select 2,GETDATE(),64

    union select 2,GETDATE(),99

    union select 3,GETDATE(),87

    -- I think that is more logical (and 1 less code line :-))

    select student_id

    ,MAX(score) as high_score

    ,CASE WHEN COUNT(*) = 3

    THEN SUM(score) - MAX(SCORE) - MIN(score)

    ELSE NULL

    END as mid_score

    ,CASE WHEN COUNT(*) > 1

    THEN MIN(score)

    ELSE NULL

    END as low_score

    from @Test_Scores

    group by student_id

    -- also possible to fill it "left-to-right" (J.C. might call it 1970's Sybase/Unix/Punch card/sequencial file style :hehe:)

    select student_id

    ,MAX(score) as high_score

    ,CASE COUNT(*)

    WHEN 3 THEN SUM(score) - MAX(SCORE) - MIN(score)

    WHEN 2 THEN MIN(score)

    ELSE NULL

    END as mid_score

    ,CASE COUNT(*)

    WHEN 3 THEN MIN(score)

    ELSE NULL

    END as low_score

    from @Test_Scores

    group by student_id

    Are you sure that hi __[blank] low is "more logical" than "hi lo __"?

    What about a potential for 10 scores?

    If you're reading it, do you want to see "hi __ __ __ __ __ __ __ __ lo" or "hi next/lo __ ...".

    Would three out of 10 be listed as "hi next_hi __ ... lo" or "hi __ ... next_lo lo"??

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • ScottPletcher (11/30/2012)


    capnhector (11/30/2012)


    ScottPletcher (11/30/2012)


    Eugene Elutin (11/30/2012)


    ScottPletcher (11/30/2012)


    ...

    In the interests of being thorough, I added a Message to my proposed solution back to them:

    SELECT

    ...as above...,

    CASE WHEN COUNT(*) > 3 THEN 'ERROR: > 3 TESTS FOUND, MID SCORE INACCURATE!' ELSE '' END AS Message

    To me, this teaches the students something important as well:

    Just because someone promises you there are only 3 values -- pinkie swear, cross their heart -- don't necessarily believe them! Either verify it 100%, or, if it's easy, add something to catch the unexpected. My sample table of data would of course have one student_id that had 4 test results and a middle value of 105 🙂 .

    That is I guess quintessence of the difference between "school" and "practice".

    Because, I would most definitely not add this check in my code!

    If someone would tell me that table should allow "only 3 values", instead of worrying about possibility of having data inconsistent at every query, I would enforce it by trigger or a constraint on computed column...

    Also, I kind of agree with Jeff on restrictions such as "single query" and "using basic sql". I would really want to see the best possible solution with showing knowledge of the most advanced SQL features instead of ability to solve irrelevant puzzles (aka SELECT EXP($) ;-)).

    If they can't solve this query without three CTEs and two table joins, that's not irrelevant to me. What better solution do you propose here with more advanced SQL?

    If they refuse to use only basic SQL for a query when I ask them to, that's not irrelevant to me either: it tells me things (good and bad).

    This will work even if you throw in a curve of 4 scores it will take the 3 earliest scores of course it uses some advanced sql (ROW_NUMBER() and PIVOT)

    declare @Test_Scores table ( student_id int, date_taken datetime, score decimal(4, 1))

    insert @Test_Scores

    select 1,GETDATE(),93

    union select 1,GETDATE() + 1,85

    union select 2,GETDATE(),88

    union select 2,GETDATE() + 1,64

    union select 2,GETDATE() + 2,99

    union select 3,GETDATE(),87

    SELECT student_id, [1],[2],[3]

    FROM (SELECT ROW_NUMBER() OVER (PARTITION BY student_id ORDER BY date_taken) rn, student_id, score

    FROM @Test_Scores)p

    PIVOT

    (MAX(Score) FOR rn IN ([1],[2],[3]))pvt

    That's not a valid solution: the tests are not hi, mid and low, in that order (should be ORDER BY score DESC).

    Easy enough change to the ROW_NUMBER()

    declare @Test_Scores table ( student_id int, date_taken datetime, score decimal(4, 1))

    insert @Test_Scores

    select 1,GETDATE(),93

    union select 1,GETDATE(),85

    union select 2,GETDATE(),88

    union select 2,GETDATE(),64

    union select 2,GETDATE(),99

    union select 3,GETDATE(),87

    SELECT student_id, [1],[2],[3]

    FROM (SELECT ROW_NUMBER() OVER (PARTITION BY student_id ORDER BY score DESC) rn, student_id, score

    FROM @Test_Scores)p

    PIVOT

    (MAX(Score) FOR rn IN ([1],[2],[3]))pvt

    I can sort of see the reasoning behind asking for it in a single query if it is extra credit. Extra credit has to be harder than the normal stuff.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • ScottPletcher (11/30/2012)


    Jeff Moden (11/30/2012)


    ScottPletcher (11/30/2012)


    Jeff Moden (11/29/2012)


    That's a good test question, Scott. The only thing I might change is requiring them to do it "in a single query". It's sometimes amazing what kind of performance people can come up with if you remove that "simple" and unnecessary restriction.

    But, unfortunately, that makes it too easy. With enough levels of CTEs, it's not that hard to figure out.

    I posted it on a forum to get some idea of what to expect from my students, and got some pretty mediocre answers from (supposedly) experienced and skilled T-SQLers.

    That's the whole problem though. I would never require someone to do this with "vanilla" code because I don't expect "vanilla" code from someone working for me. I expect accurate and high performance code that makes use of any and all features of the version of SQL Server that I'd have them working with. To wit, doing something all in one query is frequently the wrong way to do something.

    And I wouldn't want to hire someone who was incapable of writing a simple query to satisfy a simple request.

    To each his own.

    To flip this back around to what someone asked me, are you saying that if a person couldn't do this in a single query or couldn't do it in all ANSI code, that you wouldn't consider them or would you just use it as another measuring point?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • ScottPletcher (11/30/2012)


    ...

    Are you sure that hi __[blank] low is "more logical" than "hi lo __"?

    What about a potential for 10 scores?

    If you're reading it, do you want to see "hi __ __ __ __ __ __ __ __ lo" or "hi next/lo __ ...".

    Would three out of 10 be listed as "hi next_hi __ ... lo" or "hi __ ... next_lo lo"??

    I don't think we need to argue on the above...

    For me, if I have TWO different scores it's more logical to call one HIGH SCORE and another one as LOW SCORE and not logical at all to call the second one as MID_SCORE, as there is no middle.

    But I do agree, that some other people may think your way...

    Actually, if I wanted to list the score from hight to low as left to right, I would probably try to use some other column headers not "HIGH - MIDDLE - LOW". I'm not sure, but probably something like SCORE 1, SCORE 2, etc. Then, my query would be simple select with ROW_NUMBER in order by score and then cross-tab (using PIVOT or CASE...). But again, I'm looking it from practical point of you, while you might see it from theoretical/teaching position...

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • CELKO (12/1/2012)


    I use this query as extra credit for my students when I teach a SQL class. ... This is much trickier than it sounds at first. Be prepared to "guide" them by posing "leading" queries along their way to a solution 🙂 .

    How many of the kids realize that you gave them the wrong DDL? It does not have any of the constraints you gave in the specs! No key (which also enforces at least one test), no test count constraint, etc. How many of them try to use this deck of punch cards without questioning the disconnect?

    CREATE TABLE Test_Scores

    (student_id INTEGER INTEGER NOT NULL,

    test_nbr SMALLINT DEFAULT 1 NOT NULL

    CHECK (test_nbr BETWEEN 1 AND 3),

    PRIMARY KEY (student_id, test_nbr)

    test_date DATE DEFAULT CURRENT_TIMESTAMP NOT NULL,

    test_score DECIMAL(4,1) NOT NULL

    CHECK (test_score >= 0.0));

    We could use an UPDATE to sort the test_nbr to put MAX(test_score) in 1, the middle in 2 and the lowest one in 3. But that is ugly and the proposed answer is much nicer.

    No worries. They're not pedantic and supercilious enough to worry about that kind of stuff in an artificial situation where by nature one reduces the problem to its core fundamentals.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Jeff Moden (11/30/2012)


    ScottPletcher (11/30/2012)


    Jeff Moden (11/30/2012)


    ScottPletcher (11/30/2012)


    Jeff Moden (11/29/2012)


    That's a good test question, Scott. The only thing I might change is requiring them to do it "in a single query". It's sometimes amazing what kind of performance people can come up with if you remove that "simple" and unnecessary restriction.

    But, unfortunately, that makes it too easy. With enough levels of CTEs, it's not that hard to figure out.

    I posted it on a forum to get some idea of what to expect from my students, and got some pretty mediocre answers from (supposedly) experienced and skilled T-SQLers.

    That's the whole problem though. I would never require someone to do this with "vanilla" code because I don't expect "vanilla" code from someone working for me. I expect accurate and high performance code that makes use of any and all features of the version of SQL Server that I'd have them working with. To wit, doing something all in one query is frequently the wrong way to do something.

    And I wouldn't want to hire someone who was incapable of writing a simple query to satisfy a simple request.

    To each his own.

    To flip this back around to what someone asked me, are you saying that if a person couldn't do this in a single query or couldn't do it in all ANSI code, that you wouldn't consider them or would you just use it as another measuring point?

    I wouldn't hire them for anything beyond a starting DBA position; i.e., a non-DBA wanting to become a DBA. Certainly not for anything above a very junior level.

    The query is very difficult for students, but it shouldn't be that difficult for someone experienced. Again, for me personally, if it takes someone, say, 3 CTEs and two JOINs to do something that basic, I have to wonder how clearly they really think.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • CELKO (12/1/2012)

    CHECK (test_nbr BETWEEN 1 AND 3),

    Seriously, test_nbr limited to 3? What about previous classes? And classes for the next semester? Test_nbr would be identifier, not a counter.

    All the more reason to leave out such irrelevancies/distractions.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • If I were in an interview and someone asked me such a question, my answer would be that future requirements could easily change, especially in the area of the number of tests given. I'd follow that up with the question, "How much rework and retesting do you want to do if the number of tests changes to 4 or even 'N'"? Then I'd explain the different ways to calculate "mid" value in the face of such scalability and that calculating the "mid" value based on some perceived current maximum is against best practices for making resilient and bullet proof code as well as how little extra it would take to make it so.

    If the response to that was "Just do it", I'd think twice about joining the company. If I was desparately in need of the job, I'd answer their question in code just the way they want it to get the job with the deep understanding and promise to myself that I'm going to keep looking for a job where they actually want people to think. If you want a code monkey, go to the zoo. 😛

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (12/3/2012)


    If I were in an interview and someone asked me such a question, my answer would be that future requirements could easily change, especially in the area of the number of tests given. I'd follow that up with the question, "How much rework and retesting do you want to do if the number of tests changes to 4 or even 'N'"? Then I'd explain the different ways to calculate "mid" value in the face of such scalability and that calculating the "mid" value based on some perceived current maximum is against best practices for making resilient and bullet proof code as well as how little extra it would take to make it so.

    If the response to that was "Just do it", I'd think twice about joining the company. If I was desparately in need of the job, I'd answer their question in code just the way they want it to get the job with the deep understanding and promise to myself that I'm going to keep looking for a job where they actually want people to think. If you want a code monkey, go to the zoo. 😛

    Don't worry, you wouldn't have to "Think twice", because no offer would ever come anyway.

    You have NO idea of the background behind the q. Rather arrogant to assume you would.

    This was an urgent request for an immediate need. If you're so embalmed with the idea of "future requirements" that you can't respond to an emergency, then that I don't need. At 3AM, with production workers waiting, I don't want someone trying to design for something that will never exist! After all, I can get that from CELKO, and he would probably find me some international org that had a "standard" for how to put it on punch cards! 🙂

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • ScottPletcher (12/3/2012)

    At 3AM, with production workers waiting, I don't want someone trying to design for something that will never exist!

    Perhaps, but honestly I was hard pressed to answer your question at first because my initial reaction wasn't that there'd be a max of 3 tests, though I did just breeze the requirements and it is clearly stated. My personal default coding method is never trust arbitrary limits unless they're actually making my life easier and pretty dang set in stone. However, I've never coded against AS/400 (finds some wood...). Do they actually have a limit that it has to be single statement, and you can't even use a subquery or a join? Then again, I'd avoid programming against that anyway, if I had my druthers, simply because I'm not familiar with its quirks.

    However, at 3 AM, the only thing you really care about is it works both accurately and 'well enough' for performance, particularly for production when you've got a showstopper. If it runs in a few milliseconds and at that hour of the morning I (for some godforsaken reason) used 24 temp tables (or whatever the AS/400 equivalent is)... well... we'll fix it later, it's good enough; QA roll it!

    For the curious, I started to build a million row testbed for the question (what's below), just because I was curious about different takes on performance and how differently indexing may/may not affect the aggregation functions in single pass vs. multiple aggregate passes. I know single scan should always be better, was curious about the performance difference in this particular issue, not which would be most performant. However, I can't get it to make a reasonably sized test bed in a reasonable time, so if anyone has a better idea for randomizing the distribution, I'm all ears. For a mere 100 students this runs in 30-60 seconds on my home PC... which runs DiabloIII without a glitch (lot of HEAT, but that's a different discussion).

    IF OBJECT_ID( 'tempdb..#Test_Scores') IS NOT NULL

    DROP TABLE #Test_Scores

    CREATE TABLE #Test_Scores

    (student_ID INT NOT NULL,

    Date_Taken DATETIME NOT NULL,

    Score DECIMAL ( 4,1) NOT NULL

    )

    CREATE CLUSTERED INDEX idx_1 ON #Test_Scores (student_ID)

    CREATE NONCLUSTERED INDEX idx_2 ON #Test_Scores (student_ID, Score)

    INCLUDE ( Date_Taken)

    --CREATE NONCLUSTERED INDEX idx_3 ON #Test_Scores (student_ID, Date_Taken)

    --INCLUDE (Score)

    --CREATE NONCLUSTERED INDEX idx_4 ON #Test_Scores (Score)

    --INCLUDE( Date_Taken) -- StudentID as the clustered is implied inclusion.

    ; WITH tally AS

    (SELECT TOP 1000000

    ROW_NUMBER() OVER ( ORDER BY s1.[name]) AS N

    FROM

    master.sys.syscolumns as s1

    CROSS JOIN

    master.sys.syscolumns AS s2

    )

    INSERT INTO #Test_Scores (Student_ID, Date_Taken, Score)

    SELECT

    std.StudentID,

    CONVERT( DATETIME, '20100101') + n AS Date_Taken,

    (ABS(CHECKSUM(NEWID())) % 1000 ) / 10. AS Score

    FROM

    (SELECT

    N AS StudentID,

    (ABS(CHECKSUM(NEWID())) % 3) + 1 AS NumTests -- Always want at least 1 test

    FROM

    tally

    WHERE

    N <= 100 -- How many students?

    ) AS std

    JOIN

    tally AS t

    ONt.n <= std.NumTests

    SELECT * FROM #Test_Scores


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Continuous discussion on this thread, kind of shows that people has nothing much to do...

    :hehe:

    I do agree with few different points of different posters...

    I guess if such question is asked on the interview (not on the exam), you may go into offering or at least querying for the more flexible solution. I would think that interviewer will still ask to resolve it based on his strict and basic conditions, but will definitely point out that the candidate has an experience in handling and questioning real-life requirements.

    BTW, I don't think J.Moden would be asked to go for interview... Phone conversation to confirm his name, would be more than enough for most of places where SQL is taken seriously 😉

    And in opposite, employing theoretics/academics, for the real life, business critical projects, regardless of the quantity of published books, may be quite risky, as businesses are more likely in need of workable solutions ASAP, to win competitive markets, instead of "Rolls-Royce" etalon of best standards (more suitable for uni's and schools).

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • ScottPletcher (12/3/2012)


    Jeff Moden (12/3/2012)


    If I were in an interview and someone asked me such a question, my answer would be that future requirements could easily change, especially in the area of the number of tests given. I'd follow that up with the question, "How much rework and retesting do you want to do if the number of tests changes to 4 or even 'N'"? Then I'd explain the different ways to calculate "mid" value in the face of such scalability and that calculating the "mid" value based on some perceived current maximum is against best practices for making resilient and bullet proof code as well as how little extra it would take to make it so.

    If the response to that was "Just do it", I'd think twice about joining the company. If I was desparately in need of the job, I'd answer their question in code just the way they want it to get the job with the deep understanding and promise to myself that I'm going to keep looking for a job where they actually want people to think. If you want a code monkey, go to the zoo. 😛

    Don't worry, you wouldn't have to "Think twice", because no offer would ever come anyway.

    You have NO idea of the background behind the q. Rather arrogant to assume you would.

    This was an urgent request for an immediate need. If you're so embalmed with the idea of "future requirements" that you can't respond to an emergency, then that I don't need. At 3AM, with production workers waiting, I don't want someone trying to design for something that will never exist! After all, I can get that from CELKO, and he would probably find me some international org that had a "standard" for how to put it on punch cards! 🙂

    No arrogance here, Scott.

    First, there's a difference between an actual emergency and a bloody inteview question but not much of one. The emergency has to be fixed now and can be changed in the near future to handle the point of scalability.

    However, if you're really good and the manager is really good, you know that it will take about 2 minutes longer to make it relatively infinite in scalability and the manager will see the advantage. All it takes is one simple question... "What does "mid" mean if there's more than one value between the high and the low"? Both you and the manager should see that might prevent another 3AM emergency.

    So far as no offer being extended, that's fine because I don't want to work for a company that wants a code monkey. That, notwithstanding, you might be surprised by the intelligence of some companies that would, in fact, extend the offer after such an exchange. I don't know how you interview but if someone came back to me about such options as I've stated, that would be points in their favor over the candidates that did the code monkey thing and solved the problem with no comment.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Eugene Elutin (12/4/2012)


    Continuous discussion on this thread, kind of shows that people has nothing much to do...

    :hehe:

    So, not much to do, Eugene? 😛

    BTW, I don't think J.Moden would be asked to go for interview... Phone conversation to confirm his name, would be more than enough for most of places where SQL is taken seriously 😉

    Thank you for the nice thought but not true. Every interview I've ever been in has lasted for at least 2 hours. Most of the other people's interviews last somewhere between 15 and 30 minutes. "Jeff Moden" is just another guy. Even if they are enamored after they Google me, I insist on a "face to face" interview with folks. First, I want them to know I'm not Googling stuff as we speak on the phone and second, I want to know what I'm getting into. I thoroughly engage my prospective employers as if I'd been working there a thousand years to discover their personalities and what the heartbeat of the company actually sounds like.

    And in opposite, employing theoretics/academics, for the real life, business critical projects, regardless of the quantity of published books, may be quite risky, as businesses are more likely in need of workable solutions ASAP, to win competitive markets, instead of "Rolls-Royce" etalon of best standards (more suitable for uni's and schools).

    Heh... I agree and disagree at the same time. I've seen "workable" solutions that go out the door "ASAP" and come back with problems equally quick. Not a good way for the company or the developer to build a reputation for doing things right.

    In the case of the problem that Scott was good enough to share, we're not talking about a Rolls-Royce solution here. We're just talking about making sure that there's lug nuts on the go cart so the wheels don't fall off once it leaves the shop.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (12/4/2012)


    ScottPletcher (12/3/2012)


    Jeff Moden (12/3/2012)


    If I were in an interview and someone asked me such a question, my answer would be that future requirements could easily change, especially in the area of the number of tests given. I'd follow that up with the question, "How much rework and retesting do you want to do if the number of tests changes to 4 or even 'N'"? Then I'd explain the different ways to calculate "mid" value in the face of such scalability and that calculating the "mid" value based on some perceived current maximum is against best practices for making resilient and bullet proof code as well as how little extra it would take to make it so.

    If the response to that was "Just do it", I'd think twice about joining the company. If I was desparately in need of the job, I'd answer their question in code just the way they want it to get the job with the deep understanding and promise to myself that I'm going to keep looking for a job where they actually want people to think. If you want a code monkey, go to the zoo. 😛

    Don't worry, you wouldn't have to "Think twice", because no offer would ever come anyway.

    You have NO idea of the background behind the q. Rather arrogant to assume you would.

    This was an urgent request for an immediate need. If you're so embalmed with the idea of "future requirements" that you can't respond to an emergency, then that I don't need. At 3AM, with production workers waiting, I don't want someone trying to design for something that will never exist! After all, I can get that from CELKO, and he would probably find me some international org that had a "standard" for how to put it on punch cards! 🙂

    No arrogance here, Scott.

    First, there's a difference between an actual emergency and a bloody inteview question but not much of one. The emergency has to be fixed now and can be changed in the near future to handle the point of scalability.

    However, if you're really good and the manager is really good, you know that it will take about 2 minutes longer to make it relatively infinite in scalability and the manager will see the advantage. All it takes is one simple question... "What does "mid" mean if there's more than one value between the high and the low"? Both you and the manager should see that might prevent another 3AM emergency.

    So far as no offer being extended, that's fine because I don't want to work for a company that wants a code monkey. That, notwithstanding, you might be surprised by the intelligence of some companies that would, in fact, extend the offer after such an exchange. I don't know how you interview but if someone came back to me about such options as I've stated, that would be points in their favor over the candidates that did the code monkey thing and solved the problem with no comment.

    It would take far longer than 2 minutes to give the full background you wanted.

    This for a simple, introductory interview q, when I often had two more people to interview the same day.

    Just not practical. If that simple a q requires 30 minutes of background detail to get an answer, I'd hate to even have to bring up replication:

    "I'm doing merge replication and ...". It could take hours to fill in all the background on the whys/wherefores of that. Realistically there just isn't time.

    "Why merge and not transactional? What if a site changes locations?" And so on. Impossible to do all that in the space of an interview for every q.

    Without other direct knowledge, I'd believe the person probably couldn't answer the q. Typically introducing such irrelevancies is just a way to deflect the q.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

Viewing 15 posts - 46 through 60 (of 73 total)

You must be logged in to reply to this topic. Login to reply