gpt4 book ai didi

c# - 使用MySql内连接在谷歌饼图上显示数据

转载 作者:行者123 更新时间:2023-11-29 06:38:25 24 4
gpt4 key购买 nike

我需要在谷歌饼图上显示一些数据,我必须使用 2 个表格来实现这一点。表名称为authentication 和agentdetails,这两个表都有类似的名为“agentlogin”的列。 agentdetails 拥有代理的所有数据,通过身份验证我可以得到已注册代理的数量。我需要从代理详细信息中获取代理登录的数据,这些数据也出现在身份验证中,并且我想按技能2列对它们进行分组。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var options = {
title: 'Registration'
};
$.ajax({
type: "POST",
url: "adminrep.aspx/GetChartData",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
var data = google.visualization.arrayToDataTable(r.d);
var chart = new google.visualization.PieChart($("#chart")[0]);
chart.draw(data, options);
},
failure: function (r) {
alert(r.d);
},
error: function (r) {
alert(r.d);
}
});
}
</script>

public static List<object> GetChartData()
{
string query = "SELECT authentication.agentlogin, agentdetails.skill2, COUNT(authentication.agentlogin) TotalRegistration FROM agentdetails ";
query += " INNER JOIN authentication ON agentdetails.agentlogin = authentication.agentlogin WHERE agentdetails.location = 'PNQ10-Pune' GROUP BY skill2";
string MyConString = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
List<object> chartData = new List<object>();
chartData.Add(new object[]
{
"skill2", "TotalRegistration"
});
using (MySqlConnection con = new MySqlConnection(MyConString))
{
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (MySqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
chartData.Add(new object[]
{
sdr["skill2"], sdr["TotalRegistration"]
});
}
}
con.Close();
return chartData;
}
}
}

表格

我该如何完成这件事?提前致谢。

最佳答案

如果您想计算是否发生了身份验证,那么您需要LEFT连接来获取第一个表中的所有结果,而不仅仅是两个表中出现的结果

如果表之间的关系是1对1,那么每个agent只会出现一次,那么左连接上不会出现重复的resilt,并且resilt应该与您已经到达的类似

请注意,注册总数仅包含已注册的代理,而不是所有代理:

SELECT
ad.skill2,
SUM(IF( auth.agentlogin IS NULL, 1,0)) AS TotalRegistration
FROM agentdetails ad
LEFT JOIN authentication auth ON ad.agentlogin = auth.agentlogin
WHERE ad.location = 'PNQ10-Pune'
GROUP BY
ad.skill2

您的原始查询:

SELECT authentication.agentlogin, agentdetails.skill2, COUNT(authentication.agentlogin) TotalRegistration FROM agentdetails
INNER JOIN authentication ON agentdetails.agentlogin = authentication.agentlogin WHERE agentdetails.location = 'PNQ10-Pune' GROUP BY skill2;

希望有帮助

关于c# - 使用MySql内连接在谷歌饼图上显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52775629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com