此SQL查询出现以下错误
专栏' StudentSIP.StartDate'因为它在选择列表中无效 不包含在聚合函数或GROUP BY中 子句。
select concat(sc.StartDate, sc.EndDate) SIPDate,
count (sj.LOComment) WeekReviewed,
count(sjd.WeekNo) TotalWeek,
sum(sjj.TotalDaysRecord) TotalDaysRecord,
count(case sjd.JournalStatusCode when 'D' then 1 else null end) PendingComplete
from StudentJournalDate sjd
left join StudentJournal sj
on sjd.WeekNo = sj.WeekNo
left outer join
(
select sj.WeekNo,
case when RTRIM(sj.Day1Journal) = '' or sj.Day1Journal is null then 0 else 1 end +
case when RTRIM(sj.Day2Journal) = '' or sj.Day2Journal is null then 0 else 1 end +
case when RTRIM(sj.Day3Journal) = '' or sj.Day3Journal is null then 0 else 1 end +
case when RTRIM(sj.Day4Journal) = '' or sj.Day4Journal is null then 0 else 1 end +
case when RTRIM(sj.Day5Journal) = '' or sj.Day5Journal is null then 0 else 1 end +
case when RTRIM(sj.Day6Journal) = '' or sj.Day6Journal is null then 0 else 1 end +
case when RTRIM(sj.Day7Journal) = '' or sj.Day7Journal is null then 0 else 1 end as TotalDaysRecord
from StudentJournal sj
) as sjj
on sjj.WeekNo = sj.WeekNo
left outer join StudentSIP sc
on sc.AdminNo = sjd.AdminNo
答案 0 :(得分:2)
您从未告诉我们您使用的是哪个版本的SQL,但我怀疑您的 android:configChanges="orientation|keyboardHidden|screenSize"
(例如SELECT
和COUNT
)中聚合函数的存在是数据库进入分组模式。在此模式下,您只能使用SUM
中列的聚合函数或SELECT
子句中出现的列。由于GROUP BY
既不是聚合,也没有sc.StartDate
子句,因此会出现此错误。
使此错误消失的一个快速解决方法是GROUP BY
连接的开始和结束日期,即将GROUP BY
添加到当前查询的末尾:
GROUP BY CONCAT(sc.StartDate, sc.ENDDate)
答案 1 :(得分:-1)
在没有group by子句的情况下使用A ggregate函数时,sql不起作用;
ex select key1,key2,count(*),sum(*) from tableA group by key1,key2