Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
I have a sql command that selects AVG score from two tables, php/mysql, but it returns empty?
I have a sql command that selects AVG score from two tables, php/mysql, but it returns empty if one of the tables dosnt have a score for the employee..
so here it is
SELECT (
(SUM(QA_Scores.score_total) + SUM(qaform.qscore)) / (COUNT(QA_Scores.score_total) + COUNT(qaform.qscore)
)
) AS avg_score
FROM QA_Scores
LEFT JOIN qaform ON QA_Scores.score_tech = qaform.emp_id
WHERE qaform.emp_id = XXXXXX
Now, it does work perfectly IF THERE ARE SCORES ON BOTH TABLES
but the problem I am having is that there may not be a score on one of the tables.. it could be one or the other
Any workarounds?
Thank you
Shawn
Okay, still new with all this union and joining
when I run that command it states
#1054 - Unknown column 's.score' in 'field list'
So what would I do to add s.score as a temp maybe?
You have made me the happiest man alive
1000 Thanks to you!
I hope you have a great year
2 Answers
- RatchetrLv 71 decade agoFavorite Answer
You could do it as the average of all the scores from the first table + all the scores in the second table for employee XXXXX:
SELECT AVG(s.score) avg_score
FROM
(
SELECT score_total FROM QA_Scores WHERE score_tech = XXXXXX
UNION
SELECT qscore FROM qaform WHERE emp_id = XXXXXX
)s
ETA:
Take 2:
SELECT AVG(s.score) avg_score
FROM
(
SELECT score_total score FROM QA_Scores WHERE score_tech = XXXXXX
UNION ALL
SELECT qscore score FROM qaform WHERE emp_id = XXXXXX
)s
Add the score alias, and changed UNION to UNION ALL (Without ALL, duplicate rows would be removed, which would give the wrong result)
- fullemLv 44 years ago
Assuming that, based on your schema, a action picture is rented provided that it has a row in mm_rental (which probably skill it relatively is deleted from there while back), you will get a itemizing of obtainable video clips from go with movie_id, movie_title FROM mm_movie the place movie_id not IN (go with movie_id FROM mm_rental)