我有两个表,通过多对多关系通过第三个表连接。为了简化:
表A ID-A(整数) 名称(varchar) 分数(数字)
表B ID-B(int) 名称(varchar)
表AB ID-AB(int) A(外键ID-A) B(外键ID-B)
我想要的是显示B名称以及属于给定B的所有As的“分数”值的总和。但是,以下代码:
WITH "Data" AS(
SELECT "B."."Name" As "BName", "A"."Name", "Score"
FROM "AB"
LEFT OUTER JOIN "A" ON "AB"."A" = "A"."ID-A"
LEFT OUTER JOIN "B" ON "AB"."B" = "B"."ID-B")
SELECT "BName", SUM("Score") AS "Total"
FROM "Data"
GROUP BY "Name", "Score"
ORDER BY "Total" DESC
结果为每个“ BName”显示几行,其中“分数”分成这些行之间的按随机分布的增量。例如,如果Johnny的期望结果是12,April的期望结果是25,则查询可能显示以下内容:
约翰尼| 7
约翰尼| 3
约翰尼| 2
4月| 19
4月| 5
4月| 1
等
即使尝试嵌套查询并使用SUM(“ Score”)进行另一个SELECT之后,结果也相同。我不确定自己在做什么错吗?
答案 0 :(得分:1)
从public void ConvertHtmlToPfd(string htmlData)
{
ServerSocket s = new ServerSocket(0);
HtmlToPdfConverter htmlToPdfConverter = new
HtmlToPdfConverter(GetLocalIPAddress(),(uint)s.LocalPort);
htmlToPdfConverter.TriggeringMode = TriggeringMode.Auto;
htmlToPdfConverter.PdfDocumentOptions.CompressCrossReference = true;
htmlToPdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Best;
if (ContextCompat.CheckSelfPermission(Android.App.Application.Context, Manifest.Permission.WriteExternalStorage) != Permission.Granted)
{
ActivityCompat.RequestPermissions((Android.App.Activity)Android.App.Application.Context, new String[] { Manifest.Permission.WriteExternalStorage }, 1);
}
if (ContextCompat.CheckSelfPermission(Android.App.Application.Context, Manifest.Permission.ReadExternalStorage) != Permission.Granted)
{
ActivityCompat.RequestPermissions((Android.App.Activity)Android.App.Application.Context, new String[] { Manifest.Permission.ReadExternalStorage }, 1);
}
try
{
// create the HTML to PDF converter object
if (Android.OS.Environment.IsExternalStorageEmulated)
{
root = Android.OS.Environment.ExternalStorageDirectory.ToString();
}
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";
htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait;
Java.IO.File myDir = new Java.IO.File(root + "/Reports");
try
{
myDir.Mkdir();
}
catch (Exception e)
{
string message = e.Message;
}
Java.IO.File file = new Java.IO.File(myDir, filename);
if (file.Exists()) file.Delete();
htmlToPdfConverter.ConvertHtmlToFile(htmlData, "", myDir.ToString());
}
catch (Exception ex)
{
string message = ex.Message;
}
}
子句中删除Score
:
GROUP BY
查询的目的是按名称进行汇总,因此名称应单独出现在SELECT BName, SUM(Score) AS Total
FROM Data
GROUP BY BName
ORDER BY Total DESC;
子句中。通过包括分数,您将在输出中获得每个唯一名称/分数组合的记录。
答案 1 :(得分:0)
好的,我发现了我的问题。确实,我只需要按“名称”指定GROUP BY,但是我认为Firebird不允许我这样做。原来那只是一个错字。糟糕!