现有四个表 分别为:
nuser:n_id (int)(用户id) ,n_username (varchar)(用户姓名);
operator:operator_id(回答者id),operator_name(回答者姓名);
question:uq_id(int)(问题id),n_id(int)(提问用户id),uq_context(varchar)(问题内容),uq_time(datetime)(提问时间);
recode:recode_id(int)(记录id),uq_id(int)(问题id),operator_id(int)(问题需要回答者id),recode_state(bit)(回答状态0为未回答,1为已回答);
用户可以对多个回答者提问,提问几个人recode记录几条数据,该回答者回答后recode表中recode_state变为1;
用一条sql语句查询出id为6的回答者需要回答的问题的内容,提问人姓名,回答数量,提问时间,各位大侠们救命!!!
不胜感谢!!!!!

解决方案 »

  1.   

    贴建表及插入记录的SQL,及要求结果出来看看
      

  2.   

     (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式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)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  3.   

    DROP TABLE IF EXISTS `nuser`;
    CREATE TABLE `nuser` (
      `n_id` int(11) NOT NULL,
      `n_username` varchar(50) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    INSERT INTO `nuser` VALUES ('1', 'abc');DROP TABLE IF EXISTS `operator`;
    CREATE TABLE `operator` (
      `operator_id` int(11) NOT NULL,
      `username` varchar(50) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    INSERT INTO `operator` VALUES ('1', 'oper1');
    INSERT INTO `operator` VALUES ('2', 'oper2');
    INSERT INTO `operator` VALUES ('3', 'oper3');
    INSERT INTO `operator` VALUES ('4', 'oper4');
    INSERT INTO `operator` VALUES ('5', 'oper5');
    INSERT INTO `operator` VALUES ('6', 'oper6');DROP TABLE IF EXISTS `question`;
    CREATE TABLE `question` (
      `uq_id` int(11) NOT NULL,
      `n_id` int(11) NOT NULL,
      `uq_context` text NOT NULL,
      `uq_time` datetime NOT NULL,
      PRIMARY KEY (`uq_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;INSERT INTO `question` VALUES ('1', '1', 'wenti', '2011-04-27 11:36:34');
    INSERT INTO `question` VALUES ('2', '1', 'wenti2', '2011-04-27 11:36:46');DROP TABLE IF EXISTS `recode`;
    CREATE TABLE `recode` (
      `recode_id` int(11) NOT NULL,
      `uq_id` int(11) NOT NULL,
      `operator_id` int(11) NOT NULL,
      `recode_state` bit(1) NOT NULL,
      PRIMARY KEY (`recode_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;INSERT INTO `recode` VALUES ('1', '1', '1', '\0');
    INSERT INTO `recode` VALUES ('2', '1', '2', '\0');
    INSERT INTO `recode` VALUES ('3', '1', '3', '\0');
    INSERT INTO `recode` VALUES ('4', '1', '4', '\0');
    INSERT INTO `recode` VALUES ('5', '1', '6', '\0');
    INSERT INTO `recode` VALUES ('6', '2', '2', '\1');
    INSERT INTO `recode` VALUES ('7', '2', '6', '\0');查询operator_id=6的未回答问题记录得出的结果应该为 
    问题描述   提问者  回答数量  提问时间 
    wenti     abc    0        2011-04-27 11:36:34
    wenti2    abc    1        2011-04-27 11:36:46
      

  4.   

    楼主提供的测试数和结果并不匹配,希望在提供用例的时候能认真看一下,否则是浪费别人的时间。
    mysql> select uq_context,n_username,recode_state+0,uq_time
        -> from nuser a inner join question b on a.n_id=b.n_id
        ->  inner join recode c on b.uq_id=c.uq_id
        -> where c.operator_id=6;
    +------------+------------+----------------+---------------------+
    | uq_context | n_username | recode_state+0 | uq_time             |
    +------------+------------+----------------+---------------------+
    | wenti      | abc        |              0 | 2011-04-27 11:36:34 |
    | wenti2     | abc        |              0 | 2011-04-27 11:36:46 |
    +------------+------------+----------------+---------------------+
    2 rows in set (0.03 sec)mysql>
      

  5.   

    recode表的insert语句为INSERT INTO `recode` VALUES ('1', '1', '1', 0);
    INSERT INTO `recode` VALUES ('2', '1', '2', 0);
    INSERT INTO `recode` VALUES ('3', '1', '3', 0);
    INSERT INTO `recode` VALUES ('4', '1', '4', 0);
    INSERT INTO `recode` VALUES ('5', '1', '6', 0);
    INSERT INTO `recode` VALUES ('6', '2', '2', 1);
    INSERT INTO `recode` VALUES ('7', '2', '6', 0);
    5楼大侠,您查询出的第二条记录的回答数量为0,而在recode表中recode_id=6的recode_state=1,也就是说operator_id=2的回答者已经回答过该问题,因此结果中第二个问题的回答数应该为1
      

  6.   

    recode_state表示的为回答状态,而不是回答记录数
      

  7.   


    mysql> select uq_context,n_username,(select count(*) from recode where uq_id=b.u
    q_id and recode_state='\1') as cc ,uq_time
        -> from nuser a inner join question b on a.n_id=b.n_id
        ->  inner join recode c on b.uq_id=c.uq_id
        -> where c.operator_id=6;
    +------------+------------+------+---------------------+
    | uq_context | n_username | cc   | uq_time             |
    +------------+------------+------+---------------------+
    | wenti      | abc        |    0 | 2011-04-27 11:36:34 |
    | wenti2     | abc        |    1 | 2011-04-27 11:36:46 |
    +------------+------------+------+---------------------+
    2 rows in set (0.00 sec)mysql>