从Customer表中选择Latest Records

时间:2014-04-02 09:01:44

标签: php mysql

我正在尝试获取客户最新交易的记录。我正在尝试的查询是:

SELECT 
  food_rate,
  ambiance_rate,
  service_rate,
  cost_rate 
FROM
  tbl_transaction t 
  INNER JOIN tbl_feedback f 
    ON t.fid = f.fid 
WHERE date_time IN 
  (SELECT 
    MAX(date_time) 
  WHERE c_id = 1)

输出仅为单行。但它给出了语法错误。

3 个答案:

答案 0 :(得分:0)

试试这个

SELECT food_rate, ambiance_rate, service_rate, cost_rate 
from tbl_transaction t 
inner join tbl_feedback f ON t.fid=f.fid 
where c_id=1
order by date_time desc
limit 1

答案 1 :(得分:0)

试试这个:

SELECT 
  food_rate,
  ambiance_rate,
  service_rate,
  cost_rate 
FROM
  tbl_transaction t 
  INNER JOIN tbl_feedback f 
    ON t.fid = f.fid 
WHERE c_id = 1
ORDER BY date_time DESC
LIMIT 1;

答案 2 :(得分:0)

//你没有在子查询中写表名,我已经重写了查询

 SELECT 
  food_rate,
  ambiance_rate,
  service_rate,
   cost_rate 
 FROM
   tbl_transaction t 
 INNER JOIN tbl_feedback f 
   ON t.fid = f.fid 
WHERE date_time IN 
(SELECT 
MAX(date_time) from tbl_transaction
WHERE c_id = 1)