使用Access 2010,我试图按开关值分组,目前在编制代码时遇到麻烦。基本上,在我的数据库的治疗字段中,我有诸如D1,D2,D3,E1,E2,E3之类的值。第一个字母表示特定的处理类型,例如D =处理1,E =处理2。例如,我希望按“ Treatment1”和“ Treatment2”对数据进行分组。
SELECT switch(LEFT(t1.[treatment],1)='D',"Treatment1",LEFT(t1.[treatment],1)='E',"Treatment2"), count(t1.[UniqueID]) AS Total_Population, count(t2.[date]) AS DateSent, format(count(t2.[date]) / count(t1.[UniqueID]),"0.00%") AS Percentage_Sent, COUNT(IIF(t1.[requirements]='1',1,)) AS requirements_population
FROM Main_table AS t1 LEFT JOIN (SELECT t2.[ID], t2.[date] FROM Main_table AS t2 WHERE t2.date Not Like ('NA')) AS t2 ON t1.[ID] = t2.[ID]
GROUP BY [treatment]
例如,预期输出为Treatment1-x量,Treatment2-y量。但是目前,我得到了处理1和处理2的多行,因为这些表达式后面的数据不是唯一的(即D1,D2,D3,E1,E2,E3)。
答案 0 :(得分:0)
更改为:
class ESBEvent {
private String msgID;
private Date timestamp;
private String applicationName;
private String routeName;
private String eventName;
private String globalTrxID;
private String parentTrxID;
private byte[] paylod;
}
因此,您将GROUP BY LEFT(t1.[treatment], 1)
的第一个字母而不是t1.[treatment]
分组