1

我有 2 个选择语句从 2 个表中为同一个人提取数据。我知道它们可以通过连接进行组合,但我无法让语法为我工作。

查询一:

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

公共链接是用户名字段。
我想要一个结果集,它为每个学生提供用户名、天数和平均值,但我无法让加入或组合选择工作。

任何帮助表示赞赏。

4

1 回答 1

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
于 2013-03-26T21:00:15.217 回答