我有一个MySQL查询,我想执行该查询以查看谁是我工作的公司中技能X最高的员工。为此,我从我的cv_profile(skill_cv_test)中随机选择一家公司,并找到在同一雇主那里工作的所有用户。然后,我随机选择一种技能。 结果应为零或列表。 但是,当用PHPMyAdmin进行测试时,我得到的结果是我看不到任何行,但是状态显示至少有一行。 这是我收到的消息的示例:https://imgur.com/bVMH716
我一直在尝试不同的结构,甚至将查询与另一个查询“连接”在一起,使用不同的联接。
SELECT
DISTINCT(sv.usr_id),
u.first_name AS fn,
u.last_name AS ln,
c.name AS company,
s.name AS skill
FROM
(
SELECT
MAX(last_change) as date,
id,
usr_id,
skill_id
FROM skill_valuations
GROUP BY usr_id, skill_id
ORDER BY date
) sv
LEFT JOIN skill_valuations skv ON skv.last_change = sv.date
INNER JOIN
(
SELECT
DISTINCT(skct.comp_id),
skct.usr_id AS usr_id,
skct.category
FROM skill_cv_test skct
WHERE skct.end_date IS NULL AND skct.comp_id IN (SELECT comp_id FROM (SELECT comp_id FROM skill_cv_test WHERE usr_id = 1 ORDER BY RAND() LIMIT 1) x)
) uqv ON uqv.usr_id = sv.usr_id
INNER JOIN
(
SELECT skill_id
FROM usr_skills
WHERE usr_id = $uid
ORDER BY RAND()
LIMIT 1
) usq ON usq.skill_id = sv.skill_id
LEFT JOIN companies c ON c.id = uqv.comp_id
LEFT JOIN skills s ON s.id = sv.skill_id
LEFT JOIN users u ON u.id = sv.usr_id
如前所述,我希望没有结果或至少有一行结果。