Ready, steady… save!
You don’t need a chart to join in. Here are 2 ways to record your savings:
1. Cross it off
Pop a chart into your first post. Saved an amount? Cross it out! Read more »
£0.01 £0.02 £0.03
2. Write it down
Skip the chart and add updates to your first post. Read more »
“Another +£3 saved today. Go me!”
Use +£ before each new saving so it counts towards your total.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
SQL queries - Help needed please
Comments
-
SELECT firstName, lastName, employee.branchNo, branchTelephone
FROM employee, branch
WHERE positionId == 1 AND employee.branchNo == branch.branchNo
This should work for the first one.0 -
I haven't done it for a while but try this
SELECT employeeFirstName, employeeLastName, whatever you want from branch table eg branch.location from employee, branch
INNER JOIN branch
ON employee.branchId=branch.branchId
WHERE employee.positionId=1
or have you tried that already??0 -
ladymarmalade1970's query should work.
Another way is:
SELECT * FROM employee as t1 inner join branch as t2 on t1.branchNo=t2.branchNo where t1.positionId=1
For the age, you could include the following in the field list:
round(datediff(curdate(),dob)/365.25) as age
where dob is a date field in the employee table containing the date of birth, which will show as yyyy-mm-dd when you browse it.
The age calculation is not perfect and could be thrown out a year around birthdays. There is a way round it, but it gets quite complicated!I’m a Forum Ambassador and I support the Forum Team on the In My Home MoneySaving, Energy and Techie Stuff boards. If you need any help on these boards, do let me know. Please note that Ambassadors are not moderators. Any posts you spot in breach of the Forum Rules should be reported via the report button, or by emailing forumteam@moneysavingexpert.com.
All views are my own and not the official line of MoneySavingExpert.
0 -
SELECT FirstName, Lastname, DateOfBirth, CURDATE(),
DATEDIFF(year,'DateOfBirth', year,'CURDATE()') AS age
FROM employee
Where age >= 25 AND jobId = 1
This is what I came up with for the datediff one, but my error message is
#1582 - Incorrect parameter count in the call to native function 'DATEDIFF'.
This following option did actually list all employees and showed their age in years, but I couldn't get it to only show the over 25's.
But if I addSELECT FirstName, Lastname, DateOfBirth, CURDATE(),
(YEAR( CURDATE( ) ) - YEAR( dateOfBirth) ) - (RIGHT( CURDATE( ), 5) < RIGHT( dateOfBirth, 5) )
AS age FROM staff
it comes up with the error: '#1054 - Unknown column 'age' in 'where clause''WHERE age >= 25
Regarding the first question, thank you so much scottishblondie. It worked although it didn't work with the ==. I had to use just one =.
I tried that method first, so thanks ladymarmalade and victor for your suggestions. I would have tried them next.0 -
Unfortunately you have to put the entire expression in again instead of age in the where statement.
I’m a Forum Ambassador and I support the Forum Team on the In My Home MoneySaving, Energy and Techie Stuff boards. If you need any help on these boards, do let me know. Please note that Ambassadors are not moderators. Any posts you spot in breach of the Forum Rules should be reported via the report button, or by emailing forumteam@moneysavingexpert.com.
All views are my own and not the official line of MoneySavingExpert.
0 -
Hi again,
3) I need to list all the branches and give the total monthly salary paid out.SELECT branchNo, sum(AnnualSalary)/12 as MonthlySalary from employee where branchNo = 5
This statement works and gives me a 2 column table with branchNo and Monthly Salary (average) but only for one branch.
Does anyone know how to add to the statement to list all of the branch numbers?
Thanks0 -
OMG it worked - you are such a star. All of you are.
If you have a last idea of the average salary question that would be a hattrick. :j
Try something like:
SELECT branchNo,sum(AnnualSalary)/12 as MonthlySalary from employee group by branchNo
The group by is the key to that one!I’m a Forum Ambassador and I support the Forum Team on the In My Home MoneySaving, Energy and Techie Stuff boards. If you need any help on these boards, do let me know. Please note that Ambassadors are not moderators. Any posts you spot in breach of the Forum Rules should be reported via the report button, or by emailing forumteam@moneysavingexpert.com.
All views are my own and not the official line of MoneySavingExpert.
0 -
If you are using PHPMyAdmin, it implies the data is on a host accessible to the internet. With such sensitive employee data, better make darn sure it's secure. Wiser to run the DB on your own PC (if you are not doing so already).0
Confirm your email address to Create Threads and Reply
Categories
- All Categories
- 355.9K Banking & Borrowing
- 255K Reduce Debt & Boost Income
- 456.2K Spending & Discounts
- 248.4K Work, Benefits & Business
- 606.1K Mortgages, Homes & Bills
- 179K Life & Family
- 263.9K Travel & Transport
- 1.5M Hobbies & Leisure
- 16.2K Discuss & Feedback
- 37.7K Read-Only Boards