0

メソッドのタイプ (メソッド = Air または Sea) を格納するテーブル「booking_summary」があります。メソッド列に応じて、このテーブルを他の 2 つのテーブルのいずれかと結合する必要があります。

メソッドが Air の場合、参加するテーブルは booking_air であり、sea の場合は booking_sea です。この特定のページで複数のクエリを実行したくありません。

これは私の最新の試みであり、明らかに失敗しました。別名を持つ table_name は、同じクエリで必要なテーブルです。

$sql = "select case when a.shipping_method = 'Sea' then 'booking_sea' else 'booking_air' end 'table_name',
                case when a.user_id ='$active_id' then 'y' else 'no' end 'generate_access',
                case when c.mbl is NULL then 'Pending' else c.mbl end 'mbl_status',
                case when c.hbl is NULL then 'Pending' else c.hbl end 'hbl_status',
                a.*,b.user_name 
                from booking_summary a
                left join registered_users b 
                on a.user_id = b.user_id
                left join table_name c
                on a.id = c.id
                where (a.user_id = '$active_id' or a.forwarder='$active_id')";

どんなアドバイスもとても役に立ちます。ありがとう

4

2 に答える 2

1

うーん、これがうまくいくかどうかはわかりませんが、とにかく...

$sql = "select case 
                when a.user_id ='$active_id' then 'y' 
                else 'no' end 'generate_access',
            if(a.shipping_method = 'Sea',
                case when c.mbl is NULL then 'Pending' else c.mbl end,
                case when d.mbl is NULL then 'Pending' else d.mbl end ) 'mbl_status',
            if(a.shipping_method = 'Sea',
                case when c.hbl is NULL then 'Pending' else c.hbl end,
                case when d.hbl is NULL then 'Pending' else d.hbl end ) 'hbl_status',
                 a.*,b.user_name 
                from booking_summary a
                left join registered_users b  on a.user_id = b.user_id
                left join booking_sea c  on a.id = c.id
                left join bookin_air d on a.id=d.id
                where (a.user_id = '$active_id' or a.forwarder='$active_id')";
于 2013-08-26T13:17:48.697 に答える