0

私はphpページで作業しており、という名前のテーブルがあります

computer_complaint

私が望むのは、ユーザーからの最新の苦情によってこのテーブルからデータを取得することだけです。ユーザーが苦情を申し立てると、このテーブルに保存され、一意の

computer_id

問題_日付

ユーザーが苦情を申し立てた日付と時刻を入力する列です。同じユーザーが複数回苦情を申し立てることができます

今、そのユーザーの苦情の最新の詳細を表示できるクエリが必要なので、その computer_id の最後の problem_date でテーブルを並べ替える必要があります。私の現在のクエリは

select *,date_format(cc.problem_date,'%d/%m/%Y')as problem_date,ifnull(cc.attended_on,'Pending')as com_status from computer_complaint cc,computer_master cm,computer_st_complaint_mode ccm,computer_company_master cmy WHERE cc.`status`='Active' and cm.`status`='Active' and ccm.`status`='Active' and cmy.`status`='Active' and cc.computer_id=cm.computer_id and cc.method=ccm.comp_mod_id  and cm.company_id=cmy.company_id

しかし、それはその特定のIDのすべてのレコードを表示していますが、私は最新のものだけが欲しいので、すべてのcomputer_id(s)に最新の提出された苦情のみを表示させ、各IDのすべての苦情を表示しないようにします。

前もって感謝します。

4

1 に答える 1

1

それぞれの最後のものを取得するにはcc.computer_id、これを使用できます。

select *,date_format(cc.problem_date,'%d/%m/%Y')as problem_date,ifnull(cc.attended_on,'Pending')as com_status from computer_complaint cc,computer_master cm,computer_st_complaint_mode ccm,computer_company_master cmy WHERE cc.`status`='Active' and cm.`status`='Active' and ccm.`status`='Active' and cmy.`status`='Active' and cc.computer_id=cm.computer_id and cc.method=ccm.comp_mod_id  and cm.company_id=cmy.company_id ORDER BY cc.problem_date DESC GROUP BY cc.computer_id

によると、最新のエントリが表示されcc.problem_dateます。

于 2013-07-17T07:43:26.917 に答える