我一直试图根据调查数据表中的评分来回复组织者的平均评分(针对一列)。
Table: Workshops
Cols: id[pk] | title | description | survey_id[fk] | organizer_id[fk]
Table: Organizers
Cols: organizer_id[pk] | organizer_name | organizer_email | organizer_rating
Table: Surveys
Cols: survey_id[pk] | survey_desc | survey
具有用户响应的表格如下:
Table: SurveyUserResponse
Cols: s_u_r_id[pk] | username | survey_id[fk] | answer_1 | answer_2 | answer_3
答案3基本上是发言人的评级。我试图选择答案3的平均评分,并根据组织者ID加入研讨会,但它没有为组织者返回正确的平均值。
这让我感到非常难过,我不确定如何将评级纳入评级表的组织者评级栏。
非常感谢任何帮助。
修改
感谢Eduard的建议。根据您的建议,这是一个示例记录:
Table: Workshops
id | title | description | survey_id | organizer_id
---------------------------------------------------
1 | ws01 | on pottery | 1 | 1
Table: Organizers
organizer_id | organizer_name | organizer_email | organizer_rating
-----------------------------------------------------------------------
1 | Ray Dion | r.dion@ws01.com | <trying to get result here>
Table : Surveys
survey_id | survey_desc | survey
---------------------------------
1 | ws01 survey | test
Table: SurveyUserResponse
s_u_r_id | username | survey_id | answer_1 | answer_2 | answer_3
-----------------------------------------------------------------
114 | joe21331 | 1 | 4 | 5 | 3
这是我到目前为止所提出的,只是为了测试是否返回了正确的数据集:
SELECT Organizers.organizer_id, Organizers.organizer_name,
AVG(survey_user_response.answer_value_3) AS organizer_rating
FROM Organizers, survey_user_response
INNER JOIN Workshops organizer_id
ON Workshops.organizer_id = Organizers.organizer_id
ORDER BY organizer_rating DESC
答案 0 :(得分:1)
在MySQL中:
$('#btn-wordcloud').click(function() {
if (codebtn_click_counter < 1) {
alert("please hit Code Data button first");
} else {
// Get all of the words
words = [];
wordscnt = [];
var data = hot.getData();
for (i = 0; i < data.length; i++) {
for (j = 1; j < data[i].length; j++) {
if (data[i][j]) {
if (words[data[i][j]]) {
words[data[i][j]]++;
} else {
words[data[i][j]] = 1;
}
}
}
}
for (word in words) {
if (word != "None" && words[word] > 2) {
var row = {
"text": word.toUpperCase(),
"size": words[word] * 15
}
wordscnt.push(row)
}
}
if (wordscnt.length > 0) {
$('#data').hide();
var fill = d3.scale.category20();
maxSize = d3.max(wordscnt, function(d) {
return d.size;
});
minSize = d3.min(wordscnt, function(d) {
return d.size;
});
var fontScale = d3.scale.linear() // scale algo which is used to map the domain to the range
.domain([minSize, maxSize]) //set domain which will be mapped to the range values
.range([15, 80]); // set min/max font size (so no matter what the size of the highest word it will be set to 40 in this case)
if (codebtn_click_counter >= 1 && click_counter == 0) {
click_counter = ++click_counter;
d3.layout.cloud().size([1000, 500])
.words(wordscnt.sort(sortWordCountObject))
//.rotate(function() { return ~~(Math.random() * 2) * 90; })
.padding(5)
.rotate(0)
.font("Impact")
//.fontSize(function(d) { return d.size; })
.fontSize(function(d) {
return fontScale(d.size)
})
.on("end", draw)
.start();
} else {
//* How do I update the svg created?
};
function draw(words) {
d3.select("#drawing").append("svg")
.attr("width", 1000)
.attr("height", 500)
.append("g")
.attr("transform", "translate(500,250)")
.selectAll("text")
.data(words)
.enter().append("text")
.style("font-size", function(d) {
return d.size + "px";
})
.style("font-family", "Expressway")
//* .style("fill", function(d, i) { return fill(i); }) *//
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) {
return d.text;
});
}
}
}
});
在SQL Server中:
SELECT o.*,
AVG(answer_3)
FROM surveyUserResponse sur
JOIN workshops w
USING (survey_id)
JOIN organizers o
USING (organizer_id)
GROUP BY
organizer_id