Skip to content

Instantly share code, notes, and snippets.

@meiwin
Created April 3, 2012 13:42
Show Gist options
  • Save meiwin/2292104 to your computer and use it in GitHub Desktop.
Save meiwin/2292104 to your computer and use it in GitHub Desktop.
mig33 SQL (2)
-- Write a SQL query that will result in full table scan.
select *
from transaction_journal
where ucase(Receiver) = 'FOO'
-- Write a SQL query that can introduce a deadlock.
select *
from transaction_journal
for update
;
-- Write a SQL query that returns the total amount received by a user named 'foo' from a user named 'bar' for all days between 2012-01-01 to 2012-01-31
select sum(*) total
from transaction_journal
where receiver = 'foo'
and sender = 'bar'
and datecreated >= str_to_date('2012-01-01 00:00:00', '%Y-%m-%d %H:%i:%s')
and datecreated <= str_to_date('2012-01-31 23:59:59', '%Y-%m-%d %H:%i:%s')
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment