0

我有一个关于 SQL 语句的问题。

此 SQL 语句工作正常,但我也想找到 0 中的餐馆Restarurant_ID。我怎样才能在这个声明中做到这一点?

SELECT ct.*, t.*
FROM exp_channel_titles AS ct
LEFT JOIN transactions AS t ON (ct.entry_id = t.restaurant_id)
WHERE t.cardid > 0
ORDER BY t.created DESC
4

4 回答 4

2

你可以这样做

WHERE t.cardid > 0 OR t.restaurant_id=0 

如果 cardid 不强制大于 0 ,您也可以使用 AND 确保t.cardid也大于 0

于 2013-02-20T10:36:09.367 回答
1

添加AND restaurant_id = 0到你的 where 子句

于 2013-02-20T10:36:06.247 回答
1

在 PHP 中:

 <?php

        $result = mysql_query("SELECT
         ct.*, t.*
         FROM
         exp_channel_titles as ct
         LEFT JOIN
         transactions as t on (ct.entry_id = t.restaurant_id)
         WHERE
         t.cardid > 0 and t.restaurant_id=0
         order by t.created DESC");

        while($row = mysql_fetch_array($result)){
          echo $row['field'];
        }


    ?>
于 2013-02-20T10:37:39.320 回答
0
SELECT
ct.*, t.*
FROM
exp_channel_titles as ct
LEFT JOIN
transactions as t on (ct.entry_id = t.restaurant_id)
WHERE
t.cardid > 0 and t.restaurant_id=0
order by t.created DESC
于 2013-02-20T10:35:52.427 回答