Last answered:

29 May 2024

Posted on:

21 Apr 2023

1

Numbers don't match, am I missing something?

In the table salaries the count of current salaries (whose to_date is>sysday()) is 81635.

However, in the table dept_emp the amount of employees whose to_date is >sysday() = 240024

If we run the  query below, we can see that there are 158489 employees whose salary  = 0

Is it supposed to be this way? Seems counterintuitive.


select de.emp_no, count(s.to_date)
from dept_emp de
left join salaries s on (s.emp_no = de.emp_no) and (s.to_date>sysdate())
where de.to_date > sysdate()
group by de.emp_no
having count(s.to_date) = 0;



4 answers ( 0 marked as helpful)
Instructor
Posted on:

24 Apr 2023

0

Hi Eugenia!
Thanks for reaching out.


Could you please explain your question with more words and provide additional examples? Thank you.


Looking forward to your answer.
Best,
Tsvetelin

Posted on:

25 Apr 2023

0

What I am trying to say is that the amount of current employees is more than the amount of current salaries. (The query that I gave proves it). It seems counter intuitive to me, because, as far as I am concerned, every employee should have a salary. The reason I am pointing it out is because it confused me when I was trying to make sence of numbers regarding this database. 


Posted on:

21 Feb 2024

0

@Tsonkov 

Hello instructor,

@Eugenia meant to ask that when we run a query which returns the emp_no whose to_date is greater than the sysdate() on both dept_emp table and salaries table individually. The no.of rows returned is different to a great extent. Considering all the employees receive salaries and belongs to a department . She is wondering why both the values contradict.

i.e rows returned in dept_emp is higher than rows returned in salaries table whose number the fellow learner has mentioned as 240024 and 81635 respectively on the date she queried.


Instructor
Posted on:

29 May 2024

0

Hi Eugenia and Shalini!
Thanks for reaching out.


@: Shalini
Thanks for pointing this out!

@: Eugenia 

The database we’re working with is purely for learning purposes and isn't a real one. It's designed to help you practice and understand SQL queries. So, some of the anomalies you’re seeing, like employees without salaries, are likely there intentionally or just part of the exercise.

These kinds of issues give you a great opportunity to develop your problem-solving skills and learn how to handle data inconsistencies. In real-life databases, making sure the data is accurate is super important, and being able to spot and fix these kinds of anomalies is a valuable skill to have. So, take this as a chance to practice and get better at writing queries that can clean up and manage data properly.



Hope this helps.
Best,
Tsvetelin

Submit an answer