Live data from Hacker News

Our SQL interview questions

jitbit.com

71–80 of 227 posts

Re: Our SQL interview questions

#71
post #15

I could nail those with the Django ORM, but I'd struggle to write syntactically correct SQL, not having done it in a while. But it says that your test machine has MS-SQL; with the machine in front of me, I could probably puzzle it out the join quirks with a couple minutes of trial and error.

How would you solve the first one using Django ORM?

  from .models import Employee
  from django.db.models import F

  print Employee.objects.filter(
      salary__gt=F('boss__salary')
  )

Re: Our SQL interview questions

#72
I recently took an SQL skill assessment test from one of the big 'testing' sites. My first problem with the test was that it was a mix of Oracle and MS SQL, when my resume said 'MySQL'. And there were questions such as 'What is the MS SQL equivalent to the Oracle keyword xxxx?' Luckily I've used it enough to not bomb that portion. To be expected with a recruiter...

Anyway, some of the other questions were pretty silly like "Which of the following is a DDL command?", and many were SELECT statements with a syntax error that you had to pick out, and probably the one question that made sense was about the difference between WHERE and HAVING.

Re: Our SQL interview questions

#73
post #48

Earlier quoted context omitted.

True story, but such questions are just senseless. If someone knows about set-theory and the ideas behind query-languages, knowing SQL isn't a deal breaker, it's just a nice to have.

Folk generally don't study relational algebra, on its own, for fun.

They really should.

Re: Our SQL interview questions

#74
post #61

Earlier quoted context omitted.

I don't run a school. Anytime a web-developer does not know basic sql or other basic knowledge, I refuse to pay salary, and even deduct the 1$ per minute. That five minutes just cost you $10

Ignoring the fact that 1$/minute * 5minutes = 5$ -- I wonder which _knowledgeable_ person is willing to work with someone who thinks like you do...

I said I wouldn't be paying the salary + even deducting $1 which is $2 per minute.

This person did not qualify to be _knowledgeable_, as he refused to do this test ;)

Re: Our SQL interview questions

#75
post #70

"List employees (names) who have a bigger salary than their boss" SELECT e1.Name FROM Employees e1 LEFT OUTER JOIN Employees e2 ON (e1.BossID = e2.EmployeeID) WHERE e1.Salary > e2.Salary "List departments that have less than 3 people in it" SELECT d.Name, COUNT(e.EmployeeID) FROM Department d LEFT OUTER JOIN Employees e ON (d.DepartmentID = e.DepartmentID) GROUP BY d.Name HAVING COUNT(e.EmployeeID) "List all departme…

Curious question: why do you always use table aliases? To keep your query shorter? When I don't need an alias I just use the full table name for readability: SELECT Department.Name, COUNT(Employees.EmployeeID) FROM Department JOIN Employees ON Employees.DepartmentID = Department.DepartmentID GROUP BY Department.Name HAVING COUNT(Employees.EmployeeID)

Good question. I always find it easier to have the aliases because sometimes, table names are too long for me to remember. Also, tehre are times when we join the same table by itself and at that point, I use x1, x2 etc. In general, aliases always work while direct table names may not work for all cases. So i just keep it simple.

Re: Our SQL interview questions

#76
Somewhat surprisingly most web developers I know know very little SQL, having picked it up exclusively by tinkering to get things done any way whatsoever, even if clumsy or slow. In fact SQL might look deceptively simple at times, at one point I read an ANSI SQL book so I already had some formal education in SQL when I started doing webdev, but I only really learnt ANSI SQL at the university in the databases course, and then I still had to do more learning about many details of my DB server of choice (postgres), including things like spatial queries and indexes, full-text search etc., you can get huge speed ups and infrastructure simplifications by putting those kinds of things directly in the DB.

Ask people about difference between LEFT JOIN and RIGHT JOIN, or using the schema from the article, to select all attributes of employees with the highest salary in their department in pure SQL and you will see how much or how little people know, in fact many webdevs don't even understand JOINs at all!

Re: Our SQL interview questions

#77
post #69

Earlier quoted context omitted.

I came to Oracle after it adopted the ANSI syntax, so that's what I use. So my experience is the opposite of yours -- when I see the (+) I need to look up the syntax to remember if it's left or right outer.

And then I ask, hey, where's my BOOLEAN? And then I drink.

Oh god.

And the lack of a serial/autoincrement/identity type.

So. Many. Effing. Triggers.

And 32-character identifiers.

sigh

Re: Our SQL interview questions

#78
What is the preferred way to aggregate with nulls?

    SELECT  Departments.name, SUM(COALESCE(salary,0))
    FROM Departments 
    LEFT JOIN employees USING departmentID
    GROUP BY 1
The above is how I would solve the last one, but I often feel like I abuse COALESCE.

Re: Our SQL interview questions

#80

I'm not a SQL Developer, but anytime I get questions for which Google has answers to be found in 5 minutes or less, I'm quite hesitant to work there. I respect interviews that go along the lines of: "What would you do if..." after giving a detailed description of their environment. But then again I'm a tools/OSes admin, so maybe it makes more sense for my job description. But anytime guys are too focused on third opt…

I don't run a school. Anytime a web-developer does not know basic sql or other basic knowledge, I refuse to pay salary, and even deduct the 1$ per minute. That five minutes just cost you $10

We are going to have to deduct a few dollars for your lack of basic multiplication.
Post reply on HN