0
SELECT      ps.job_no, ps.booking_no,
            ps.type,ps.shipped_by, ps.invoice_no,
            ps.transporters_id,ps.clients_id,ps.return_terminal,
            ps.destinations_id,ps.forwarder_name,              
            containers.container_size,containers.container_no,
            containers.truck_no,
            ps.driver_cell_no,ps.shipping_line_name,
            containers.cro_no,vessels.vessel_name,vessels.eta,
            containers.empty_pickup_point,containers.loading_point,
            ps.particular 
  FROM      planning_sheet AS ps 
                LEFT JOIN vessels 
                    ON vessels.bookingno= ps.booking_no
                LEFT JOIN containers 
                    ON containers.bookingno = ps.booking_no
GROUP BY ps.clients_id 

我是构建此类复杂查询的新手,查询定义如下,我想要在此查询中针对“clients_id”的所有记录我得到针对此查询的一条记录。

我还想在“type = 0”时写“Air”或“type =1”而不是在“type”列中写“Sea”。

4

4 回答 4

1

GROUP BY在使用子句之前,您必须先聚合一些列。有关一些聚合函数,请参见此处。但是如果要修改 中的输出type,可以使用 inLineCase语句。

SELECT  ....,
        CASE ps.`type`
           when 0 then 'Air'
           when 1 then 'Sea'
        END as `type`,
        ....
FROM    .... 
于 2012-07-09T08:04:37.197 回答
0

尝试这个..

SELECT      ps.job_no, ps.booking_no,
            CASE ps.type WHEN 0 THEN 'Air' WHEN 1 THEN 'Sea' ELSE 'None' END 
            as PLAN_TYPE,
            ps.shipped_by, ps.invoice_no,
            ps.transporters_id,ps.clients_id,ps.return_terminal,
            ps.destinations_id,ps.forwarder_name,              
            containers.container_size,containers.container_no,
            containers.truck_no,
            ps.driver_cell_no,ps.shipping_line_name,
            containers.cro_no,vessels.vessel_name,vessels.eta,
            containers.empty_pickup_point,containers.loading_point,
            ps.particular 
  FROM      planning_sheet AS ps 
                LEFT JOIN vessels 
                    ON vessels.bookingno= ps.booking_no
                LEFT JOIN containers 
                    ON containers.bookingno = ps.booking_no

根据数据类型使用ps.type

CASE ps.type WHEN 0 THEN 'Air' WHEN 1 THEN 'Sea' ELSE 'None' END

或者

CASE ps.type WHEN '0' THEN 'Air' WHEN '1' THEN 'Sea' ELSE 'None' END

于 2012-07-09T08:16:48.450 回答
0

你可以把它放到你的查询中

select
CASE type 
      when '0' then 'Air'
      when '1' then 'Sea'
END as type 
于 2012-07-09T07:59:54.123 回答
0

尝试这个::

SELECT      ps.job_no, ps.booking_no,
            ps.type,ps.shipped_by, ps.invoice_no,
            ps.transporters_id,ps.clients_id,ps.return_terminal,
            ps.destinations_id,ps.forwarder_name,              
            containers.container_size,containers.container_no,
            containers.truck_no,
            ps.driver_cell_no,ps.shipping_line_name,
            containers.cro_no,vessels.vessel_name,vessels.eta,
            containers.empty_pickup_point,containers.loading_point,
            ps.particular ,
           CASE ps.type when '0' then 'Air'
when '1' then 'Sea'
END as type
  FROM      planning_sheet AS ps 
                LEFT JOIN vessels 
                    ON vessels.bookingno= ps.booking_no
                LEFT JOIN containers 
                    ON containers.bookingno = ps.booking_no
于 2012-07-09T08:02:10.320 回答