select 学生,sum(case when 书名='小说' then 数量 end), sum(case when 书名='散文' then 数量 end),sum(case when 书名='其他' then 1 end) from .... group by 学生
刚学的: select 学生 ,sum(case 书名 when '小说' then 数量 else 0 end) as '小说' , sum(case 书名 when '散文' then 数量 else 0 end) as '散文' , sum(case 书名 when '其他' then 数量 else 0 end) as '其他' from table group by 学生
dim q as string,ds as ADODB.Recordset ds.open "select distinct 书名 as a from ..."..... do until ds.eof if q<>"" then Q=Q & "," q=q & sum(case when 书名='" & ds("a") &"' then 数量 end), ds.movenext loop ds.close ds.open "select 学生, " & Q & "from .... group by 学生"...
sum(case when 书名='散文' then 数量 end),sum(case when 书名='其他' then 1 end) from .... group by 学生
select 学生 ,sum(case 书名 when '小说' then 数量 else 0 end) as '小说' , sum(case 书名 when '散文' then 数量 else 0 end) as '散文' , sum(case 书名 when '其他' then 数量 else 0 end) as '其他' from table group by 学生
dim q as string,ds as ADODB.Recordset
ds.open "select distinct 书名 as a from ...".....
do until ds.eof
if q<>"" then Q=Q & ","
q=q & sum(case when 书名='" & ds("a") &"' then 数量 end),
ds.movenext
loop
ds.close
ds.open "select 学生, " & Q & "from .... group by 学生"...
可以把第一个表读出来,然后程序中作个判断,再显示出来。