MySQL 咨询
(mysql)表:z_hzmanage 如下:
创建表;
CREATE TABLE `z_hzmanage` (
`z_id` int(11) NOT NULL auto_increment,
`z_yyh` varchar(25) default NULL,
`z_uname` varchar(10) NOT NULL,
`z_sex` int(10) unsigned NOT NULL default '0',
`z_age` varchar(10) default '0',
`z_area` int(15) unsigned NOT NULL default '0',
`z_tel` varchar(15) default NULL,
`z_jzbz1` varchar(25) default NULL,
`z_jzbz2` varchar(25) default NULL,
`z_dzdate` varchar(30) default NULL,
`z_yydate` varchar(30) default NULL,
`z_isxf` int(5) unsigned NOT NULL default '0',
`z_source` int(10) unsigned NOT NULL default '0',
`z_isfbz` int(10) unsigned NOT NULL default '0',
`z_iszsl` int(10) unsigned NOT NULL default '0',
`z_jzys` int(10) unsigned NOT NULL default '0',
`z_content` text,
`z_isstate` int(5) unsigned NOT NULL default '0',
`z_class` int(10) unsigned NOT NULL default '0',
`z_username` varchar(10) default NULL,
`z_systemdate` date NOT NULL default '0000-00-00',
PRIMARY KEY (`z_id`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=gbk;
插入数据如下:
INSERT INTO z_hzmanage VALUES ('20', 'VB004', '张三', '1', '59', '3', '15986598989', '2', null, '2013-07-22', '2013-07-22', '1', '8', '1', '1', '4', '前列腺增生情况', '1', '43', '贾荣暖', '2013-07-07');
INSERT INTO z_hzmanage VALUES ('22', 'A120', '李想', '1', '25', '27', '13661324126', '13', null, '', '2013-07-25', '0', '2', '0', '0', '0', '尿痛、尿不尽', '0', '46', '于欣', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('23', 'B08136', '张宏', '2', '23', '3', '13341093286', '13', null, '2013-07-22', '2013-07-22', '0', '2', '0', '0', '0', '不育', '0', '49', '刘宗利', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('24', 'G0111109', '单国明', '1', '60', '3', '13520360453', '13', null, '2013-07-22', '2013-07-22', '0', '2', '0', '0', '0', '泌尿系统感染 有血尿的情况', '1', '43', '贾荣暖', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('25', 'X08137', '李传山', '2', '36', '3', '18639376779', '13', null, '', '2013-07-10', '0', '2', '0', '0', '0', '早泄', '0', '49', '刘宗利', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('26', 'X0111110', '吴晓东', '1', '28', '3', '18301422176', '13', null, '2013-07-22', '2013-07-22', '0', '2', '0', '0', '0', '', '0', '43', '贾荣暖', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('27', 'G0121110', '董艳秋', '2', '29', '13', '13836838645', '13', null, '', '2013-07-22', '0', '1', '0', '0', '0', '', '0', '43', '贾荣暖', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('28', 'X08135', '张明心', '1', '24', '3', '13611260617', '13', null, '', '2013-07-08', '0', '2', '0', '0', '0', '', '0', '49', '刘宗利', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('29', '08134', '高峰', '1', '24', '3', '15719585829', '1', null, '', '2013-07-08', '0', '2', '0', '0', '0', '', '0', '49', '刘宗利', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('30', 'G0121112', '张旭', '1', '42', '13', '18045933999', '13', null, '', '2013-07-10', '0', '1', '0', '0', '0', '', '0', '43', '贾荣暖', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('31', 'x08231', '吴友军', '2', '24', '29', '15612351449', '0', '0', '', '2013-07-15', '0', '10', '0', '0', '0', '', '0', '49', '刘宗利', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('32', 'B012108', '赵言松', '1', '40', '13', '18010030698', '13', null, '', '2013-07-22', '0', '11', '0', '0', '0', '', '0', '43', '贾荣暖', '2013-07-08');
INSERT INTO z_hzmanage VALUES ('33', 'Q1912 ', '魏有军', '1', '50', '3', '13691092145', '13', null, '2013-07-22', '2013-07-23', '0', '2', '0', '0', '0', '', '0', '52', '岳晶晶', '2013-07-09');
INSERT INTO z_hzmanage VALUES ('34', 'Q1921', '王宪明', '1', '50', '11', '13832099758', '13', null, '', '2013-07-22', '0', '2', '0', '0', '0', '', '0', '52', '岳晶晶', '2013-07-09');
INSERT INTO z_hzmanage VALUES ('35', '11', '李海涛', '1', '33', '11', '13930723909', '1', null, '', '', '0', '2', '0', '0', '0', '', '0', '52', '岳晶晶', '2013-07-09');
INSERT INTO z_hzmanage VALUES ('36', '11', '郝晓飞', '1', '28', '0', '13311129002', '0', null, '', '', '0', '2', '0', '0', '0', '', '0', '52', '岳晶晶', '2013-07-09');
INSERT INTO z_hzmanage VALUES ('37', 'Q1913', '付晓亮', '1', '30', '0', '13321123651', '咨询', '阴茎短小', '', '', '1', '2', '1', '1', '1', '', '1', '52', '岳晶晶', '2013-07-09');
INSERT INTO z_hzmanage VALUES ('38', 'J13101', '郝志', '2', '32', '29', '15810203044', '7', null, '', '', '0', '2', '0', '0', '0', '', '0', '50', '赵学广', '2013-07-09');
INSERT INTO z_hzmanage VALUES ('39', 'J13106', '秦东梅', '2', '32', '3', '18932845983', '13', null, '', '', '0', '2', '0', '0', '0', '', '0', '50', '赵学广', '2013-07-09');
INSERT INTO z_hzmanage VALUES ('40', 'X13203', '刘镇男', '1', '27', '0', '13038964566', '男性不育', '血精', '', '', '0', '2', '0', '0', '0', '', '0', '50', '赵学广', '2013-07-09');
INSERT INTO z_hzmanage VALUES ('41', 'ytf123', '王二麻子', '1', '28', '1', '13146577982', '炎症', '精索炎', '', '2013-07-18', '0', '3', '0', '0', '1', '54645', '0', '27', '夏新愿', '2013-07-18');
INSERT INTO z_hzmanage VALUES ('42', 'mvcphp12', '王二麻子', '1', '27', '2', '13146577982', '复查', '他院术后治疗无效或感染', '', '2013-07-19', '0', '3', '0', '0', '0', '', '0', '52', '岳晶晶', '2013-07-19');
z_class(帮定的用户ID)、z_username(用户的姓名)、z_yydate(预约日期)、z_dzdate(到诊日期)
我现在想要的工能是,查询每个用户的姓名(姓名不能重复)、然后再查询统计,昨日预约日期、昨日到诊日期、本月预约日期、本月到诊日期的个数
例如这样显示:
用户姓名 昨日预约(2013-07-23) 昨日到诊(2013-07-23) 本月预约(单位:人) 本月到诊(单位:人)
贾荣暖 (6人) (6人) (6人) (6人)
刘宗利 (5人) (5人) (5人) (5人)
夏新愿 (1人) (1人) (1人) (1人)
于欣 (1人) (1人) (1人) (1人)
岳晶晶 (6人) (6人) (6人) (6人)
赵学广 (3人) (3人) (3人) (3人)
就是统计出每个用户的,昨日预约多少人、昨日到诊多少人、本月预约多少人、本月到诊多少人,然后点击数字,可以看到详细的,昨日预约人数、昨日到诊人数、本月预约人数、本月到诊人数。
我弄了一下午没弄出来,请各位帮帮忙啊,感激不尽。先谢谢啦!。
回复讨论(解决方案)
建议分4次分别统计查询出昨日预约昨日到诊。。。的各个人员的病人数量,然后整合起来吧
SELECT z_username, SUM(CASE WHEN z_yydate = '2013-07-22' THEN 1 ELSE 0 END) AS 昨日预约,SUM(CASE WHEN z_dzdate = '2013-07-22' THEN 1 ELSE 0 END) AS 昨日到诊,SUM(CASE WHEN z_yydate LIKE '2013-07%' THEN 1 ELSE 0 END) AS 本月预约,SUM(CASE WHEN z_dzdate LIKE '2013-07%' THEN 1 ELSE 0 END) AS 本月到诊FROM z_hzmanage GROUP BY z_class
Nach dem Login kopieren
3楼代码可实现
我连你前面的都没看懂
三楼高手,不错学习了
肯定是高手啦,你看你家的级别有多高,学习了。。。。
。。。写的不错呀,竟然没给分?