SQL语句在ACCESS通过,但写在MFC里面不能通过
表a
no1 name class score
1 A 初一1 60
2 B 初二2 70
3 C 初一2 30
4 D 初二1 80
5 E 初一1 45
统计各年级score>=60人数
统计出
初一 1
初二 2
初三 0
在ACCESS使用以下语句通过,但在MFC里面就不能通过,为什么呢?
select left(class,2),sum(iif(score>=60,1,0))
from
(
select * from a
union
select distinct 1,'','初一',0 from a
union
select distinct 1,'','初二',0 from a
union
select distinct 1,'','初三',0 from a
)
group by left(class,2)
------解决方案--------------------"SELECT left(grade,2) AS cntgrade, sum(iif(latedate >= '%s' and latedate <= '%s' and grade like '%s',1,0)) AS num FROM (select * from studentlate union select distinct '','','初一','','','','' from studentlate union select distinct '','','初二','','','','' from studentlate union select distinct '','','初三','','','','' from studentlate union select distinct '','','高一','','','','' from studentlate union select distinct '','','高二','','','','' from studentlate union select distinct '','','高三','','','','' from studentlate) GROUP BY left(grade,2)":
这句显示出来是什么?用变量赋值,显示一下
------解决方案--------------------
调试中打开出你的SQL的实际内容是什么?
#7楼 则语法都不对。
SELECT left(grade,2) AS cntgrade, sum(iif(latedate >= '2010-03-01' and latedate <= '2010-03-01' and grade like '%%',1,0)) AS num FROM (select * from studentlate union select distinct '','','初一','','','','' from studentlate union select distinct '',''
1. 日期用 #2010-03-01# 而不是 '2010-03-01'
2. select distinct '','','初一','','','','' from studentlate union select distinct '','' UNION的字段个数不匹配。