Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
pilotraam
Starting Member
1 Post |
Posted - 2014-05-03 : 15:38:57
|
Heyfor the first querry, the 2 tables are: 1)customers: id (int), gender (char), birth_date (date)2)salaries: id (int), month (int), salary (int)I need to print out, for each MALE customer, who was born IN THE 70'S, his average quarterly salary, for the 2nd calendar quarter.That's what I've tried:SELECT avg (salary)from employee e, salaries swhere e.id=s.id and gender='m' and birthdate between '1970-01-01'and '1979-12-31'and month between '5' and '8'group by salaryI get running query, but empty output (even if it's wrong to be empty)*****************************************For the 2nd query, the 2 tables are:1)customers: id (int), name(varchar(255)), gender(char)2)relations: id1(int), id2(int), relation_type(varchar(255)) ***note - realtion_type is stuff like: 'married'/'divorce'/none/friends/house_commitee/ETC...I need to print out all the WOMEN that are MARRIED to guys called 'MIKE'What I've tried to no avail is:select distinct namefrom customers inner join relations where customers.gender='f' relations.relation_type='married' and relations.id1='avi'or relations.id2='avi'But I think and feel I'm completely loss and off track with this oneI really need accurate instructions how to solve those 2 (It's not homework, I swear, It's for job interview preperation). Thank you very much in advance |
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2014-05-04 : 10:13:23
|
quote: Originally posted by pilotraamIt's not homework, I swear, It's for job interview preperation
Ranting onI will try to be as gentle as I possibly can: Are you f****** kidding?So its better to fool a potential new employer where you every day have to prove your skills, than a teacher who give you at better grade than you deserve and you probably will never use?These are probably the simplest of sql tasks you will get in the database business. Imagine your potentially new imployer, colleagues or customers increasing the severity of the tasks.You want to get a job in the database bussiness, fair enough. But this requires months and months (even years) of studying, and can't be done over the weekend - don't show off skills you don't have (yet).Ranting offFirst sql: don't use "group by" on same field you use with an aggreagate function. Also 2nd calendar quarter would be months 4, 5 and 6.Second sql: the relation table holds the customer ids, don't use specific value ('avi'). Also you need to read from customer table twice - once for the female, second for the male. Hint: use table aliases. |
|
|
|
|
|
|
|