Click to See Complete Forum and Search --> : please help with my assignment on simple mysql queries
anky666
02-10-2006, 06:08 AM
We have to build an EMP table with ten rows that illustrate the operation of these queries, and a DEPT table with five rows, with one department that has no employees assigned to it.
pLEASE HELP WITH SINGLE SELECT STATEMENT
1. List each employee and the other employees who earn more than that employee.
2. List the name of each employee and the percent of total company payroll that is earned by that employee.
chazzy
02-10-2006, 12:41 PM
1) I highly doubt any of us would do your homework for you.
2) You can't expect us to even consider it without knowing how the table's constructed (ie the columns, the keys, relations, etc)
anky666
02-10-2006, 03:39 PM
Hi
I knw how to construct table...and i already done the major part of this, its just that, i am not able to do this couple of queries.
I would appreciate if you can help me out in this.
chazzy
02-10-2006, 03:42 PM
I can't help you out if you don't tell me what the table looks like.
anky666
02-10-2006, 03:47 PM
there is two table in the database:
1. employee (eno, ename, salary, dept no)
it has 10 rows
and other table is dept table:
dept (deptno, dname)
it has 5 rows.
where dept.deptno=employee.deptno
i know, its simple, but i m realy stuck in this.
chazzy
02-10-2006, 04:18 PM
Ok to answer your question then, based on your tables:
1) is only applicable if you pass a particular user, like you can find everyone that makes more than person #2 and that would be:
SELECT ename FROM employee WHERE salary > (SELECT salary FROM employee where eno = 'your_input') ORDER BY salary desc;
2) this should be:
select ename, salary / (select sum(salary) FROM employee) from employee;
you might need to fix some syntax errors. but check on the phrasing of question 1, as it is not something done in MySQL.
anky666
02-10-2006, 04:52 PM
thanks a lot, for this help.
Can u suggest me a good sql book or any online tutorial with lots of examples?
chazzy
02-10-2006, 07:30 PM
I find this one good for newer people
http://www.amazon.com/gp/product/0764577328/sr=8-1/qid=1139617778/ref=pd_bbs_1/102-9770403-4932942?%5Fencoding=UTF8