0

我正在输出一个游轮列表以显示可用性状态,但是我在每个舱室状态下多次获得每个游轮,我只想要游轮,那么如果所有舱室都售罄,则输出的状态应该是 C,否则为 A

这是我的疑问

<?php
$maketemp = "CREATE TEMPORARY TABLE temp (
                 `sailingId` varchar(5) NOT NULL,
                 marketCurrency varchar(3),
                 `Status` varchar(1)
             )";

mysql_query( $maketemp, $connection ) or
    die ( "Sql error : " . mysql_error ( ) );

$inserttemp = "INSERT INTO
                   temp
               SELECT
                   code AS sailingId,
                   'USD' AS marketCurrency,
                   CASE
                       WHEN fares_usa.status = 'sold_out' THEN 'C'
                   END AS Status
               FROM
                   cruises,
                   fares_usa
               WHERE
                   live ='Y' AND
                   cruises.id = fares_usa.cruise_id";

mysql_query( $inserttemp, $connection ) or
    die ( "Sql error : " . mysql_error ( ) );

$select = "SELECT sailingId, marketCurrency, Status FROM temp";

$export = mysql_query ( $select, $connection ) or
    die ( "Sql error : " . mysql_error( ) );

$fields = mysql_num_fields ( $export );
4

1 回答 1

0

所以我就是这样做的...

 $inserttemp = "INSERT INTO temp SELECT code AS sailingId, 'USD' AS marketCurrency, CASE WHEN GROUP_CONCAT(DISTINCT status) = 'Sold Out' THEN 'C' ELSE 'A' END AS Status FROM cruises, fares_usa WHERE live ='Y' AND cruises.id = fares_usa.cruise_id GROUP BY cruises.code";

结果 !

于 2012-04-30T08:03:02.197 回答