我有2个select语句从同一个人的2个表中提取数据。我知道他们可以通过连接组合,但我无法让语法为我工作。
查询1:
SELECT SUBSTRING_INDEX(username,'@',1) AS username,
COUNT(username) as count,
ROUND(
SUM(
CONVERT(SUBSTRING(contribution_score, -2), UNSIGNED INTEGER) +
CONVERT(SUBSTRING(focused_score, -2), UNSIGNED INTEGER) +
CONVERT(SUBSTRING(prepared_score, -2), UNSIGNED INTEGER) +
CONVERT(SUBSTRING(work_score, -2), UNSIGNED INTEGER)
)/COUNT(username)/76*100)
as average
FROM project_rubrics
GROUP BY username
LIMIT 0, 90
查询2:
SELECT username,COUNT(username) as days FROM logon GROUP BY username
常用链接是用户名字段 我想要一个结果集,它给出了每个学生的用户名,天数和平均值,但我无法获得联接或组合选择。
感谢任何帮助。
答案 0 :(得分:0)
你可以做一个子查询。
SELECT SUBSTRING_INDEX(username,'@',1) AS username,
COUNT(username) as count,
ROUND(
SUM(
CONVERT(SUBSTRING(contribution_score, -2), UNSIGNED INTEGER) +
CONVERT(SUBSTRING(focused_score, -2), UNSIGNED INTEGER) +
CONVERT(SUBSTRING(prepared_score, -2), UNSIGNED INTEGER) +
CONVERT(SUBSTRING(work_score, -2), UNSIGNED INTEGER)
)/COUNT(username)/76*100)
as average,
(SELECT COUNT(username) as days FROM logon WHERE logon.username=project_rubrics.username GROUP BY username) as username_count
FROM project_rubrics
GROUP BY username
LIMIT 0, 90