· 8 years ago · Apr 16, 2018, 06:36 AM
1CREATE TABLE IF NOT EXISTS `treatments` (
2`id` int(11) NOT NULL auto_increment,
3`account_id` int(11) NOT NULL,
4`places_id` int(11) NOT NULL,
5`user_id` int(11) NOT NULL,
6`lc_id` int(11) NOT NULL,
7`lc_name` varchar(250) NOT NULL,
8`fullname` varchar(150) NOT NULL,
9`phone` varchar(20) NOT NULL,
10`tema` varchar(150) NOT NULL,
11`text` varchar(5000) NOT NULL,
12`status` enum('1', '2', '3', '4') NOT NULL default '1',
13`type` enum('1', '2', '3', '4', '5') NOT NULL default '1',
14`priority` enum('1', '2', '3', '4', '5') NOT NULL default '1',
15`control` enum('1', '2') NOT NULL default '1',
16`del` int(1) NOT NULL default '0',
17`time` int(11) NOT NULL,
18`replytime` int(11) NOT NULL,
19`sroktime` int(11) NOT NULL,
20`date` varchar(11) NOT NULL,
21PRIMARY KEY (`id`),
22KEY `account_id` (`account_id`),
23KEY `places_id` (`places_id`),
24KEY `user_id` (`user_id`),
25KEY `lc_id` (`lc_id`)
26) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
27
28SELECT `treatments`.*, (SELECT COUNT(*) FROM `treatments` WHERE `treatments`.`lc_id`=`users`.`id`) AS `treatmentscount` FROM `treatments` WHERE `places_id` IN (3, 1, 2) ORDER BY `id` DESC LIMIT 0, 20