我最近接管了一个职位来管理多个数据库并创建多个报告。
我目前正在攻击前一名员工的报告是在MS Visual Studio中开发的。尝试从Demo_Chapter_Events.CE_EVENT_TYPE列中获取总计数,以根据filter ='SOCIAL'返回总计。
COUNT()返回有关GROUP BY的多个错误。是否有更简单的方法将COUNT()函数应用于所有其他SELECT(ed)行?提前致谢。当前报告代码如下所列。
for (String line : Files.realAllLines(Paths.get(filename)) {
Student st = new Student();
String[] data= line.split(";");
int id = Integer.parseInt(data[0]);
st.setId(id);
}
答案 0 :(得分:0)
为了我的可读性,重新格式化了代码:使用内联视图获取ce_Event_Types的数量并仅限于社交;将该表的所有限制条件移至该内联视图。
这种方法消除了由于肉体问题引起的人为计数通胀问题。
SELECT Name.ID AS Expr2
, Name.MEMBER_TYPE
, Name.STATUS
, Name.COMPANY
, Demo_Chapter.CH_UNIVERSITY
, CONVERT(VARCHAR(10), Demo_Chapter.CH_INSTALLED_DATE, 101) AS ChInstlDate
, CONVERT(VARCHAR(10), Demo_Chapter.CH_INACTIVE_DATE, 101) AS ChInctvDate
, CONVERT(VARCHAR(10), Demo_Chapter.CH_SEC_INACTIVE_DATE, 101) AS ChSecDate
, CONVERT(VARCHAR(10), Demo_Chapter.CH_REINSTALLED_DATE, 101) AS ChReInstall
, CONVERT(VARCHAR(10), Demo_Chapter.CH_THIRD_INSTALL, 101) AS ThrdInstall
, CONVERT(VARCHAR(10), Demo_Chapter.CH_FOURTH_INSTALL, 101) AS FrthInstall
, CONVERT(VARCHAR(10), Demo_Chapter.CH_TH_INACTIVE_DATE, 101) AS ThInctvDate
, Demo_Chapter.CH_TH_INACTIVE_REASON
, CONVERT(VARCHAR(10), Demo_Chapter.CH_FR_INACTIVE_DATE, 101) AS FrInctvDate
, Demo_Chapter.CH_FR_INACTIVE_REASON
, Demo_Chapter.CH_CARNEGIE_BASIC
, Demo_Chapter.CH_CARNEGIE_SS
, Demo_Chapter.CH_CARNEGIE_UNDER
, Demo_Chapter.CH_CARNEGIE_ENROLL
, Demo_Chapter.CH_ATHL_CONF
, Demo_Chapter.CH_UG_ENROLL
, Demo_Chapter.CH_NUM_WMN_STUD
, Demo_Chapter.CH_SEC_INACTIVE_REASON
, Demo_Chapter.CH_INACTIVE_REASON
, Demo_Chapter.CH_RECRUIT_TIME
, Demo_Chapter.CH_TERMS
, Demo_Academic.AA_CHAPTER_GPA
, Demo_Academic.AA_TERM
, Demo_Academic.AA_YEAR
, CONVERT(VARCHAR(10), Demo_Chapter_Events.CE_EVENT_DATE, 101) AS EvntDate
, DEC.CE_EVENT_TYPE
, DEC.cnt
FROM Name
INNER JOIN Demo_Chapter
ON Name.ID = Demo_Chapter.ID
INNER JOIN (SELECT id, count(CE_EVENT_TYPE) as cnt, CE_EVENT_TYPE
FROM Demo_Chapter_Events
WHERE CE_EVENT_TYPE = 'SOCIAL'
AND Demo_Chapter_Events.CE_EVENT_DATE BETWEEN
CONVERT(DATETIME, '2015-08-01 00:00:00', 102)
AND CONVERT(DATETIME, '2015-12-31 00:00:00', 102)
GROUP BY id, CE_EVENT_TYPE) DCE
ON Name.ID = DCE.ID
LEFT OUTER JOIN Demo_Academic
ON Name.ID = Demo_Academic.ID
WHERE (Name.MEMBER_TYPE = 'CCHP')
AND (Name.STATUS IN ('A', 'SUSP'))
AND (Demo_Academic.AA_TERM = 'SPRING')
AND (Demo_Academic.AA_YEAR = '1415')