sqlのサブクエリを使用して、値を取得しようとしていますが、サブクエリで取得したものに同じカラム名があり、エイリアスを指定していますが、うまく取得できず、Duplicate column name 'time'のようなエラーがかえってきてしまうのですが、エイリアスを二重に指定などして取得することは可能なのでしょうか?
下記の①を②の形に変えても改善しませんでした....
原因が、サブクエリ内の,a.timeとb.timeの箇所だとわかっているのですが、解決方法がわかりませんでした...
下記がテーブルとsql文になります。
よろしくお願いします。
// ① select i.`date`,i.`company_id`,i.`name`,i.`clock_in`,i.`clock_out`,i.`rest`,i.`sum`,i.`note`,j.`time` FROM attendance as i left join (select a.`company_id`,a.`name`,a.`date`,a.`time`,b.`time` from pc_log a left join pc_log b on(a.`company_id`=b.`company_id` and a.`date`=b.`date`) where (a.`in_out`='in' and b.`in_out`='out') order by a.`company_id`,a.`date`,a.`in_out`,b.`company_id`,b.`date`,b.`in_out`) as j on (i.`company_id`=j.`company_id` and i.`date`=j.`date`)
// ② select i.`date`,i.`company_id`,i.`name`,i.`clock_in`,i.`clock_out`,i.`rest`,i.`sum`,i.`note`,j.a.`time`,j.b.`time` FROM attendance as i left join (select a.`company_id`,a.`name`,a.`date`,a.`time`,b.`time` from pc_log a left join pc_log b on(a.`company_id`=b.`company_id` and a.`date`=b.`date`) where (a.`in_out`='in' and b.`in_out`='out') order by a.`company_id`,a.`date`,a.`in_out`,b.`company_id`,b.`date`,b.`in_out`) as j on (i.`company_id`=j.`company_id` and i.`date`=j.`date`)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/02/03 14:12