NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Certainly! Here are the SQL queries for each of your requests:

1. Find workers with the same first name from the `Worker` table:

```sql
SELECT FirstName, COUNT(*) AS NameCount
FROM Worker
GROUP BY FirstName
HAVING COUNT(*) > 1;
```

2. Retrieve Worker ID, Working Title, Department, and Joining Date from the `Worker` and `Title` tables:

```sql
SELECT W.WorkerID, T.WorkingTitle, W.Department, W.JoiningDate
FROM Worker W
INNER JOIN Title T ON W.WorkerID = T.WorkerID;
```

3. Find the worker who received the highest bonus in the shortest time:

```sql
SELECT B.WorkerID, MAX(B.BonusAmount) AS HighestBonus
FROM Bonus B
INNER JOIN Worker W ON B.WorkerID = W.WorkerID
GROUP BY B.WorkerID
ORDER BY MIN(B.BonusDate - W.JoiningDate) ASC
LIMIT 1;
```

4. Calculate the total bonus amount paid by the company:

```sql
SELECT SUM(BonusAmount) AS TotalBonusAmount
FROM Bonus;
```

5. Calculate the duration from an employee's joining date to when they received a bonus:

```sql
SELECT W.WorkerID, DATEDIFF(MONTH, W.JoiningDate, MIN(B.BonusDate)) AS DurationToBonus
FROM Worker W
LEFT JOIN Bonus B ON W.WorkerID = B.WorkerID
GROUP BY W.WorkerID, W.JoiningDate;
```

6. Sort the Worker table by their joining dates:

```sql
SELECT * FROM Worker
ORDER BY JoiningDate;
```

7. Find how many workers have not received a bonus with their Worker ID, first name, salary, and department:

```sql
SELECT W.WorkerID, W.FirstName, W.Salary, W.Department
FROM Worker W
LEFT JOIN Bonus B ON W.WorkerID = B.WorkerID
WHERE B.WorkerID IS NULL;
```

8. Sort the Worker table by department based on the highest bonus received:

```sql
SELECT W.WorkerID, W.Department, MAX(B.BonusAmount) AS HighestBonus
FROM Worker W
LEFT JOIN Bonus B ON W.WorkerID = B.WorkerID
GROUP BY W.WorkerID, W.Department
ORDER BY HighestBonus DESC, W.Department;
```

9. Find workers whose first names start with 'S':

```sql
SELECT * FROM Worker
WHERE FirstName LIKE 'S%';
```

10. Update a new employee in the Worker and Bonus tables:

```sql
-- Insert the new worker into the Worker table
INSERT INTO Worker (WorkerID, FirstName, LastName, Salary, JoiningDate, Department)
VALUES (7, 'New', 'Employee', 60000, '2023-09-01', 'New Department');

-- Insert a bonus record for the new worker
INSERT INTO Bonus (WorkerID, BonusDate, BonusAmount)
VALUES (7, '2023-09-15', 2500);
```

Please note that these queries are based on the assumption that the tables already exist and have the specified columns.
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.