我有个资料借阅表,如下所示,记录了用户借阅请求:
"ID" "LENDPKIIB" "LENDTIME" "FUTUNAME" "LENDPKIIA"
"1 " "5000" "29-12月-08" "测试" "测试"
"11" "5000" "29-1月 -08" "测试" "测试"
"14" "4542" "05-1月 -10" "实际材料图" "店子地区金矿普查地质报告"
"15" "4542" "05-1月 -10" "实际设计图" "普查地质报告"
"16" "4542" "05-1月 -10" "测试" "普查地质报告"
"17" "5000" "05-1月 -10" "测试" "测试"
其中,LENDPKIIB相同的代表同一份资料中的不同文件。想统计某时间段内用户借阅的资料数,比如以上记录的统计结果应该是4次(同一天中借阅记录的合并为一次),直接用count(LENDPKIIB)或distinct都不能满足要求,想问问这种sql语句怎么写?

解决方案 »

  1.   

    按照LENDPKIIB和时间分组统计
    SELECT count(LENDPKIIB) 
    FROM TAB
    GROUP BY LENDPKIIB ,LENDTIME
      

  2.   


    select LENDPKIIB,lendtime,count(*) from 表名 group by LENDPKIIB,lendtime
      

  3.   

    其实我就想要一个结果,类似于select count(LENDPKIIB) from readtable,查询结果就是一个汇总数
      

  4.   

    用了group by就是分组结果了,不是汇总后的结果
      

  5.   

    看看这个
    select count(*) from (
    select count(*)from 表名 group by LENDPKIIB,lendtime) a
      

  6.   


    select count(distinct LENDPKIIB||LENDTIME) from tb;
      

  7.   

    楼上正解,我就是想汇总统计LENDPKIIB的个数,单纯用count(LENDPKIIB)或distinct都不行,还要考虑时间不同。