Thursday, September 17, 2015

SQL Queries

Given 2 tables:

Asset
-------
Id  Name
2   Appl
3   Goog
4   HP
4   HP
5   AMZN

Price table
------------
Date Id Price
Jan1 1  10
Jan2 2   20
Jan2 4   40
Jan3 5   50

Write a query to find duplicates in Asset table:

select * from Asset group by id where count(id) > 1;

Write a query to display the prices of all assets on Jan2:

select a.name, p.price from Price p, Asset a
where p.date = 'Jan2' and p.id = a.id;

No comments:

Post a Comment