遇到此查询的问题
评论表中有3行具有不同的日期时间,我想要客户列表和最后评论created_date / updated_date。 但没有最后评论客户与客户分组
SELECT * FROM(
SELECT MAX(comments.`date_updated`), customer.id AS vid, comments.`date_updated` AS dts, comments.`id` AS comments_id, comments.* FROM customer
INNER JOIN comments ON comments.`customer_id` = customer.`id`
WHERE customer.`id` IN ('')
) AS v
GROUP BY v.`vid` LIMIT 0,50
答案 0 :(得分:1)
您为最新double now=time(0);
cout << as::datetime << as::local_time << "Local time is: "<< now << endl;
cout << as::gmt << "GMT Time is: "<< now <<endl;
cout << as::time_zone("EST") << "Eastern Standard Time is: "<< now <<endl;
date_updated
或使用内部联接
SELECT c.id AS vid, co.`date_updated` AS dts, co.`id` AS comments_id, co.*
FROM customer c
INNER JOIN comments co ON co.`customer_id` = c.`id`
LEFT JOIN comments co1 ON co.`customer_id` = co1.`customer_id` AND co.date_updated < co1.date_updated
WHERE co1.customer_id IS NULL AND c.`id` IN ('')
答案 1 :(得分:0)
你忘了按条款排序
SELECT * FROM(
SELECT MAX(comments.`date_updated`), customer.id AS vid, comments.`date_updated` AS dts, comments.`id` AS comments_id, comments.* FROM customer
INNER JOIN comments ON comments.`customer_id` = customer.`id`
WHERE customer.`id` IN ('')
) AS v
GROUP BY v.`vid` LIMIT 0,50
ORDER BY created_date desc;