我有一个查询,该查询给出了445条记录,这些记录中的每条记录都是其各自组的第一条记录。 我需要修改这样的查询 所有显示的记录应该是它们各自组的最后一条记录。
这是针对运行MySQL 5.6的Linux服务器。
SELECT t.product_title,t.price,t.currency,t.product_name,count(ms.id) as
total_sale,ms.date_sales as last_transaction
FROM tags as t LEFT JOIN mysales AS ms on t.product_id = ms.product_id
WHERE t.seller_fid=632403 and t.price>0 and ms.price>0 and t.store_status=1
group by t.product_id
order by ms.date_sales desc
我尝试使用子查询,但查询无法执行并发出错误。
SELECT * from (select
t.product_title,ms.date_sales as last_transaction
FROM tags as t LEFT JOIN mysales AS ms on t.product_id = ms.product_id
WHERE t.seller_fid=632403 and t.price>0 and ms.price>0 and
t.store_status=1) as `Records`
group by tags.product_id
order by mysales.date_sales desc
此查询给出诸如以下错误 “组声明”中的未知列“ tags.product_id”
请提供有关处理方式以及我做过的任何错误的建议。