我对SQL语句有疑问。
这个SQL语句工作正常,但我也想找到Restarurant_ID
中有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
ORDER BY t.created DESC
答案 0 :(得分:2)
你可以通过
来做到这一点WHERE t.cardid > 0 OR t.restaurant_id=0
如果卡的强制要求不大于0,您也可以使用AND来确保t.cardid
也大于0
答案 1 :(得分:1)
将AND restaurant_id = 0
添加到您的where子句
答案 2 :(得分: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'];
}
?>
答案 3 :(得分: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