mysql - get rows with latest effective date -
hi have table given. want result grouping parent_type,parent_id , result must of latest effective date.
create table `abc` ( `id` char(36) not null, `name` varchar(150) default null, `date_entered` datetime default null, `date_modified` datetime default null, `modified_user_id` char(36) default null, `created_by` char(36) default null, `assigned_user_id` char(36) default null, `description` text, `deleted` tinyint(1) default '0', `effective_date` date default null, `parent_type` varchar(100) default null, `parent_id` char(36) default null, `share_type` varchar(50) default null, `amount` double default '0', primary key (`id`), key `idx_assigned_del` (`assigned_user_id`,`deleted`) ) engine=myisam default charset=utf8; /*!40101 set character_set_client = @saved_cs_client */; -- -- dumping info table `sharemetas` -- lock tables `abc` write; /*!40000 alter table `sharemetas` disable keys */; insert `abc` values ('bd40acfd-cc79-8bd9-85a8-542bbce80bea',null,'2014-10-01 08:36:11','2014-10-01 08:36:11','1','1','60beffe2-5168-a3b5-b3e0-53e32109a6b5',null,0,'2014-10-01','bedcharges',null,'percent',10),('be06671f-c0ae-ff9d-cae3-542bbca7ba92',null,'2014-10-01 08:36:11','2014-10-01 08:36:11','1','1','60beffe2-5168-a3b5-b3e0-53e32109a6b5',null,0,'2014-10-01','bedcharges','6ebba940-4f7d-f5e4-fa33-53e3600c11e6','percent',12),('be9adac8-4651-6a18-54f1-542bbc14d95c',null,'2014-10-01 08:36:11','2014-10-01 08:36:11','1','1','60beffe2-5168-a3b5-b3e0-53e32109a6b5',null,0,'2014-10-01','bedcharges','a573477d-6756-3e62-9582-53e3619f975a','rupees',22),('bf12ec5d-9a31-ec98-4cf0-542bec172c2e',null,'2014-10-01 12:00:31','2014-10-01 12:00:31','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-10-01','billabletreatmentcharges',null,'percent',10),('bfc707eb-6f5b-fdab-5c34-542becaa31b3',null,'2014-10-01 12:00:31','2014-10-01 12:00:31','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-10-01','charges',null,'percent',15),('c05961fa-b635-b141-0664-542bece3572e',null,'2014-10-01 12:00:31','2014-10-01 12:00:31','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-10-01','labamounts',null,'percent',20),('c0e78f31-d619-c029-1603-542beca7f69a',null,'2014-10-01 12:00:31','2014-10-01 12:00:31','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-10-01','vaccinationamounts',null,'percent',25),('c1a27b80-0d9c-0c20-da90-542bec18d38f',null,'2014-10-01 12:00:31','2014-10-01 12:00:31','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-10-01','visitcharges',null,'percent',30),('bf141f2b-78d4-b6d0-0f73-542bed015448',null,'2014-10-01 12:01:19','2014-10-01 12:01:19','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-08-01','billabletreatmentcharges',null,'percent',5),('bfdba18d-7e6c-1388-f3d1-542bedb7613d',null,'2014-10-01 12:01:19','2014-10-01 12:01:19','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-08-01','charges',null,'percent',10),('c0a6fc38-0615-440a-2664-542bed92ff8c',null,'2014-10-01 12:01:19','2014-10-01 12:01:19','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-08-01','labamounts',null,'percent',15),('c1372f58-572a-4df1-3424-542bed6e3419',null,'2014-10-01 12:01:19','2014-10-01 12:01:19','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-08-01','vaccinationamounts',null,'percent',20),('c1e2f1e6-cadd-f01f-d06f-542bed9cefbc',null,'2014-10-01 12:01:19','2014-10-01 12:01:19','1','1','136050e0-0835-6def-204d-53e335191a46',null,0,'2014-08-01','visitcharges',null,'percent',25),('591f912c-2e4e-0798-9965-54322d9b2b3f',null,'2014-10-06 05:47:48','2014-10-06 05:47:48','1','1','aae43bba-4c44-c47b-dc3f-542936f8cd05',null,0,'2014-10-06','charges','6b51c07d-d0a5-44d8-03ec-53e345366677','percent',10),('65bdb62f-abee-9ca4-64d6-54322d5ce98a',null,'2014-10-06 05:47:48','2014-10-06 05:47:48','1','1','aae43bba-4c44-c47b-dc3f-542936f8cd05',null,0,'2014-10-06','charges','5193d15f-43c3-600f-280a-54009bc440d1','percent',20),('3298ac05-d47b-8bef-e9ec-5432316a9f9e',null,'2014-10-06 06:06:17','2014-10-06 06:06:17','1','1','aae43bba-4c44-c47b-dc3f-542936f8cd05',null,0,'2014-10-06','charges',null,'percent',5);
my query follow
select `id` , `effective_date` , `parent_type` , `parent_id` , `share_type` , `amount` `abc` 1 grouping `parent_type` , `parent_id` limit 0 , 30
but m not getting amount , id latest effective date
here it:
select `id` , max(`effective_date`) effective_date , `parent_type` , `parent_id` , `share_type` , `amount` `abc` 1 grouping `parent_type` , `parent_id` limit 0 , 30
have fun
mysql
No comments:
Post a Comment