Friday, 15 January 2010

Sort column from within the rows on date mysql php -


I have a table with activated_at and is_paying columns where I dated 2015-03-17 16:06:12 date like The time is stored, the Is_paying column is a boolean column that will be 0 by default by 1 or 0, now I want to sort the items in the is_paying and activated_date category. For example, I have a record in my table

  item_id is active_card active 14186 1 2015-03-17 23:40:45 13647 1 2015-03-17 12:43:52 4404 0 2015- 03-16 11:58:15 14313 1 2015-03-16 10:42:24 3806 0 2015-03-15 12:37:36 10716 1 2015-03-15 11:01:32  

Now I like the production

  14186 1 2015-03-17 23:40:45 13647 1 2015-03-17 12:43:52 14313 1 2015 -03 -16 10:42:24 4404 0 2015-03-16 11:58:15 10716 1 2015-03-15 11:01:32 3806 0 2015-03-15 12:37:36  < / Pre> 

It should prioritize the activated_at date, within it must be at the top I_paying is set to 1 if at the top, then any Can help me

So far let me select this

> item. Item ID (items (items.activated_at) = DATE (now ()) items.is_paying Items sorted by sort_order group as sort order, sorted by order to sort items by item.activ_card

With the expected result, it seems that you want to sort the date first and then is_playing In descending order, you can select

  * from the table_name command according to date (activated_at) desc, is_playing desc;  

Here is the test case

  mysql> Create table test (ITIID int, isping et, activated_at that time); The query is ok, affected 0 rows (0.09 seconds) mysql & gt; Insert test values ​​(14186,1, '2015-03-17 23:40:45'), (13647,1, '2015-03-17 12:43:52'), (4404,0, '2015- 03-16 11:58:15 '), (14313,1,' 2015-03-16 10:42:24 '), (3806,0,' 2015-03-15 12:37:36 '), ( 10716,1, '2015-03-15 11:01:32'); Mysql & gt; * From the test order described by the date (active_at), select I_playing; + --------- + ------------ + --------------------- + | Item_ID | Is_playing | Activated_at | + --------- + ------------ + --------------------- + | 14186 | 1 | 2015-03-17 23:40:45 | | 13647 | 1 | 2015-03-17 12:43:52 | | 14313 | 1 | 2015-03-16 10:42:24 | | 4404 | 0 | 2015-03-16 11:58:15 | | 10716 | 1 | 2015-03-15 11:01:32 | | 3806 | 0 | 2015-03-15 12:37:36 | + --------- + ------------ + --------------------- + 6 in rows set (0.00 seconds)  

No comments:

Post a Comment