-1
我想知道每场比赛的次数。

我需要这样的结果:

-------------------------------------------------- ----

    游戏计数
    --------- ---------
    横跨美国的银 5
    第 2 组 7
    游戏 3 10   


背景资料:

    如果不存在“maf_game”,则创建表(
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `name` varchar(250) NOT NULL,
      主键(`id`)
    ) 引擎=InnoDB 默认字符集=latin1 AUTO_INCREMENT=2 ;



    插入“maf_game”(“id”、“name”)值
    (1,“美国农业”);


    如果不存在“maf_game_attempts”,则创建表(
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `userid` varchar(100) NOT NULL,
      `sessionid` varchar(100) NOT NULL,
      `gid` int(11) 非空,
      `status` varchar(50) NOT NULL,
      `attempttime` 日期时间不为空,
      主键(`id`)
    ) 引擎=InnoDB 默认字符集=latin1 AUTO_INCREMENT=23 ;




    插入`maf_game_attempts`(`id`、`userid`、`sessionid`、`gid`、`status`、`attempttime`)值
    (1, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '开始', '2013-03-25 18:58:14'),
    (2,'JOQHOIGNUFEC945','hcn27d3i1kemmgubvti8ic3p87',1,'开始','2013-03-25 18:59:02'),
    (3,'JOQHOIGNUFEC945','hcn27d3i1kemmgubvti8ic3p87',1,'开始','2013-03-25 18:59:33'),
    (4, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '结束', '2013-03-25 19:00:41'),
    (5, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '开始', '2013-03-25 19:01:38'),
    (6, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '开始', '2013-03-25 19:01:44'),
    (7, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '开始', '2013-03-25 19:01:48'),
    (8, 'AXDUYNBAUIGC268', 'o9u8tno9qvrj8cfja2g1c516f5', 1, '开始', '2013-03-25 19:01:49'),
    (9, 'ZKHBILGVNJBB040', '8h8r13pnad0ftitsdjt9co49p0', 1, '开始', '2013-03-25 19:01:54'),
    (10, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '开始', '2013-03-25 19:02:08'),
    (11, 'AXDUYNBAUIGC268', 'o9u8tno9qvrj8cfja2g1c516f5', 1, '开始', '2013-03-25 19:02:09'),
    (12, 'ZKHBILGVNJBB040', '8h8r13pnad0ftitsdjt9co49p0', 1, '开始', '2013-03-25 19:02:10'),
    (13, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '结束', '2013-03-25 19:02:15'),
    (14, 'AXDUYNBAUIGC268', 'o9u8tno9qvrj8cfja2g1c516f5', 1, '结束', '2013-03-25 19:02:18'),
    (15,'ZKHBILGVNJBB040','8h8r13pnad0ftitsdjt9co49p0',1,'完成','2013-03-25 19:02:20'),
    (16,'JOQHOIGNUFEC945','hcn27d3i1kemmgubvti8ic3p87',1,'开始','2013-03-25 19:50:30'),
    (17, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '开始', '2013-03-25 19:50:37'),
    (18, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '开始', '2013-03-25 19:50:45'),
    (19, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '结束', '2013-03-25 19:50:51'),
    (20, 'JOQHOIGNUFEC945', 'bb57a1nfodomuf0i01pcojs0f2', 1, '开始', '2013-03-25 19:52:58'),
    (21,'JOQHOIGNUFEC945','bb57a1nfodomuf0i01pcojs0f2',1,'开始','2013-03-25 19:53:01'),
    (22,'JOQHOIGNUFEC945','bb57a1nfodomuf0i01pcojs0f2',1,'结束','2013-03-25 19:53:08');


    如果不存在“maf_game_stats”,则创建表(
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `userid` varchar(100) NOT NULL,
      `sessionid` varchar(100) NOT NULL,
      `gid` int(11) 非空,
      `qid` int(11) 非空,
      `result` varchar(50) NOT NULL,
      `accesstime` 日期时间不为空,
      主键(`id`)
    ) 引擎=InnoDB 默认字符集=latin1 AUTO_INCREMENT=23 ;


    插入`maf_game_stats`(`id`、`userid`、`sessionid`、`gid`、`qid`、`result`、`accesstime`)值
    (1, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, 16, '0', '2013-03-25 18:58:14'),
    (2, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, 14, '0', '2013-03-25 18:59:02'),
    (3, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, 12, '1', '2013-03-25 18:59:33'),
    (4, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, 9, '0', '2013-03-25 19:00:41'),
    (5, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, 5, '0', '2013-03-25 19:01:37'),
    (6, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, 6, '0', '2013-03-25 19:01:43'),
    (7, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, 1, '1', '2013-03-25 19:01:48'),
    (8, 'AXDUYNBAUIGC268', 'o9u8tno9qvrj8cfja2g1c516f5', 1, 9, '0', '2013-03-25 19:01:49'),
    (9, 'ZKHBILGVNJBB040', '8h8r13pnad0ftitsdjt9co49p0', 1, 14, '1', '2013-03-25 19:01:54'),
    (10, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, 15, '1', '2013-03-25 19:02:08'),
    (11, 'AXDUYNBAUIGC268', 'o9u8tno9qvrj8cfja2g1c516f5', 1, 7, '0', '2013-03-25 19:02:09'),
    (12, 'ZKHBILGVNJBB040', '8h8r13pnad0ftitsdjt9co49p0', 1, 6, '1', '2013-03-25 19:02:10'),
    (13, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, 14, '0', '2013-03-25 19:02:15'),
    (14, 'AXDUYNBAUIGC268', 'o9u8tno9qvrj8cfja2g1c516f5', 1, 6, '0', '2013-03-25 19:02:18'),
    (15, 'ZKHBILGVNJBB040', '8h8r13pnad0ftitsdjt9co49p0', 1, 13, '1', '2013-03-25 19:02:20'),
    (16, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, 6, '0', '2013-03-25 19:50:30'),
    (17, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, 9, '0', '2013-03-25 19:50:37'),
    (18, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, 1, '1', '2013-03-25 19:50:45'),
    (19, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, 4, '0', '2013-03-25 19:50:51'),
    (20, 'JOQHOIGNUFEC945', 'bb57a1nfodomuf0i01pcojs0f2', 1, 16, '0', '2013-03-25 19:52:58'),
    (21, 'JOQHOIGNUFEC945', 'bb57a1nfodomuf0i01pcojs0f2', 1, 13, '0', '2013-03-25 19:53:01'),
    (22, 'JOQHOIGNUFEC945', 'bb57a1nfodomuf0i01pcojs0f2', 1, 1, '0', '2013-03-25 19:53:08');

-------------------------------------------
问:昨天查询好,但我需要不结束“结束”,“完成”匿名用户喜欢
“sessionid” uj24ookkdcr3ris0cpbf82dd14 他的用户有 1 次尝试,而 eqs39lv506p150esr274e9a810 用户有 1 次尝试,请帮助...?


如果不存在“maf_game”,则创建表(
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(250) NOT NULL,
  主键(`id`)
) 引擎=InnoDB 默认字符集=latin1 AUTO_INCREMENT=2 ;


插入“maf_game”(“id”、“name”)值
(1,“美国农业”);



如果不存在“maf_game_attempts”,则创建表(
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `userid` varchar(100) NOT NULL,
  `sessionid` varchar(100) NOT NULL,
  `gid` int(11) 非空,
  `status` varchar(50) NOT NULL,
  `attempttime` 日期时间不为空,
  主键(`id`)
) 引擎=InnoDB 默认字符集=latin1 AUTO_INCREMENT=31 ;

插入`maf_game_attempts`(`id`、`userid`、`sessionid`、`gid`、`status`、`attempttime`)值
(1, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '开始', '2013-03-25 18:58:14'),
(2,'JOQHOIGNUFEC945','hcn27d3i1kemmgubvti8ic3p87',1,'开始','2013-03-25 18:59:02'),
(3,'JOQHOIGNUFEC945','hcn27d3i1kemmgubvti8ic3p87',1,'开始','2013-03-25 18:59:33'),
(4, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '结束', '2013-03-25 19:00:41'),
(5, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '开始', '2013-03-25 19:01:38'),
(6, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '开始', '2013-03-25 19:01:44'),
(7, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '开始', '2013-03-25 19:01:48'),
(8, 'AXDUYNBAUIGC268', 'o9u8tno9qvrj8cfja2g1c516f5', 1, '开始', '2013-03-25 19:01:49'),
(9, 'ZKHBILGVNJBB040', '8h8r13pnad0ftitsdjt9co49p0', 1, '开始', '2013-03-25 19:01:54'),
(10, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '开始', '2013-03-25 19:02:08'),
(11, 'AXDUYNBAUIGC268', 'o9u8tno9qvrj8cfja2g1c516f5', 1, '开始', '2013-03-25 19:02:09'),
(12, 'ZKHBILGVNJBB040', '8h8r13pnad0ftitsdjt9co49p0', 1, '开始', '2013-03-25 19:02:10'),
(13, 'PEHICJWEBEGA391', 'tpv2ebuhtnv5a8thfmltarsl65', 1, '结束', '2013-03-25 19:02:15'),
(14, 'AXDUYNBAUIGC268', 'o9u8tno9qvrj8cfja2g1c516f5', 1, '结束', '2013-03-25 19:02:18'),
(15,'ZKHBILGVNJBB040','8h8r13pnad0ftitsdjt9co49p0',1,'完成','2013-03-25 19:02:20'),
(16,'JOQHOIGNUFEC945','hcn27d3i1kemmgubvti8ic3p87',1,'开始','2013-03-25 19:50:30'),
(17, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '开始', '2013-03-25 19:50:37'),
(18, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '开始', '2013-03-25 19:50:45'),
(19, 'JOQHOIGNUFEC945', 'hcn27d3i1kemmgubvti8ic3p87', 1, '结束', '2013-03-25 19:50:51'),
(20, 'JOQHOIGNUFEC945', 'bb57a1nfodomuf0i01pcojs0f2', 1, '开始', '2013-03-25 19:52:58'),
(21,'JOQHOIGNUFEC945','bb57a1nfodomuf0i01pcojs0f2',1,'开始','2013-03-25 19:53:01'),
(22,'JOQHOIGNUFEC945','bb57a1nfodomuf0i01pcojs0f2',1,'结束','2013-03-25 19:53:08'),
(23, 'GXJVKQTQIJMU436', 'uj24ookkdcr3ris0cpbf82dd14', 1, '开始', '2013-03-26 10:02:02'),
(24, 'PEHICJWEBEGA391', 'eqs39lv506p150esr274e9a810', 1, '开始', '2013-03-26 10:05:06'),
(25, 'PEHICJWEBEGA391', 'eqs39lv506p150esr274e9a810', 1, '开始', '2013-03-26 10:05:12'),
(26, 'EHHYWVGQZKLA633', 'cptl7mvvb88r764n0654avc1l5', 1, '开始', '2013-03-26 10:17:40'),
(27, 'EHHYWVGQZKLA633', 'cptl7mvvb88r764n0654avc1l5', 1, '开始', '2013-03-26 10:17:47'),
(28, 'EHHYWVGQZKLA633', 'cptl7mvvb88r764n0654avc1l5', 1, '开始', '2013-03-26 10:17:56'),
(29,'EHHYWVGQZKLA633','cptl7mvvb88r764n0654avc1l5',1,'结束','2013-03-26 10:18:05'),
(30, 'EHHYWVGQZKLA633', 'cptl7mvvb88r764n0654avc1l5', 1, '开始', '2013-03-26 10:18:17');




4

1 回答 1

2

简而言之,这是如何做到的:

Select maf_game.name as daname , count(maf_game_attempts.id) as danum from maf_game,maf_game_attempts where maf_game_attempts.gid=maf_game.id and maf_game_attempts.status='over';

您可以丢弃状态或将其更改为您需要的状态,我认为 over 意味着播放。

于 2013-03-25T14:39:38.433 回答