Mysql在连接两个表后按日期排序多个列

时间:2015-08-03 13:10:17

标签: php mysql database datetime

enter image description here

现在我想在2015-08-04 2015-08-04的中间栏目应该在同一个订单上,2015-08-05应该在两个栏目中排列,就好像两个日期匹配它们应该在两列的顺序相同,可能就像我的sql查询的分类帐格式

SELECT i.* , it.name AS type,td.qty AS issue, td.is_from_stock AS issue_qty_type,v.name AS vendor,o.name AS branch,td.date_from AS issue_date,l.name AS location,td.user AS user,td.remarks AS remarks, os.opening_quantity AS initial_stock,os.remaining_stock AS opening_quantity,os.opening_quantity_unit_price As opening_unit
                         FROM ". $this->tbl_inventories ." AS i 
                        LEFT JOIN ". $this->tbl_inventorytypes ." AS it ON i.type_id = it.id
                        LEFT JOIN ". $this->tbl_distribution ." AS td ON td.item_id = i.item_id AND td.user_branch = i.user_branch

我确实喜欢ORDER BY purchased_date,td.date_from

1 个答案:

答案 0 :(得分:2)

首先,对您提供的图像有点具体。我认为不可能直接按照日期对MySQL提取的数据进行排序,因为MySQL数据输出代表每组数据的单行。 您必须分解为多个查询并将它们放在相应的数组中,以便您可以将数据过滤到最终数组中,即您必须将数据重新排列到新数组中并将其显示到您拥有快照的表中。