我有四张表,产品表,版本表,任务表,用例表,
希望能查询例如执行日期是特定日期的用例总数
以及和这些用例关联的任务数
以及和这些任务关联的版本数
以及和这些版本关联的产品数。
必须要去掉重复的记录。
产品表通过产品Id和版本版本关联,版本表通过版本Id和任务表关联,任务表通过任务Id和用例表关联

解决方案 »

  1.   

     (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  2.   

    一定要写全吗,写全太复杂了,我用的是MySQL,简写一下:
    product(pid,pname)
    version(vid,vname,pid)
    task(tid,tname,vid)
    case(cid,cname,tid,executetime)
    我想拿到case表中2010年三月执行的用例总数,以及和这些用例关联的任务数,以及和这些任务关联的版本数,以及和这些版本关联的产品数,我想应该用连接查询吧,但因为用的是Hibernate框架,不知道怎样写,大家能提点意见,写出最基本的SQL语句也行
      

  3.   

    给出测试用例。你的create table 语句和 insert 语句。不需要写全。如果仅从你的 #2楼 提供信息,别人如何在自己机器上测试呢?  你需要的输出结果是什么样?   参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
      

  4.   

    先猜个谜,能不能猜中看天意了。我想拿到case表中2010年三月执行的用例总数
    select count(*) from case where executetime between '2010-03-01' and  '2010-03-31' ,以及和这些用例关联的任务数,
    select (*) from case inner join task using (tid) where executetime between '2010-03-01' and  '2010-03-31' 
    以及和这些任务关联的版本数,
    select (*) from case inner join task using (tid) inner join version using (vid) where executetime between '2010-03-01' and  '2010-03-31' 
    以及和这些版本关联的产品数,
    select (*) from case inner join task using (tid) inner join version using (vid) inner join product using(pid) where executetime between '2010-03-01' and  '2010-03-31' 
      

  5.   

    恭喜你你猜中了,谢谢了,但必须要去掉重复的记录。
    最后一个我可以这样写吗
    case表中2010年三月执行的用例总数,以及和这些用例关联的任务数,以及和这些任务关联的版本数,以及和这些版本关联的产品数,
    select count(distict(cid,tid,vid,pid)) from case inner join task using (tid) inner join version using (vid) inner join product using(pid) where executetime between '2010-03-01' and '2010-03-31'  在矫正一下,就是这样