Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SQL语句中执行此操作_Sql - Fatal编程技术网

如何在SQL语句中执行此操作

如何在SQL语句中执行此操作,sql,Sql,我对SQL语句有一个问题 此SQL语句工作正常,但我还想查找其餐厅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 在where子句中添加和restaurant\u id=0在wher

我对SQL语句有一个问题

此SQL语句工作正常,但我还想查找其
餐厅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

在where子句中添加
和restaurant\u id=0
在where子句中添加
和restaurant\u id=0
,您可以通过

WHERE t.cardid > 0 OR t.restaurant_id=0 
如果cardid不是必须大于0的,您也可以使用和来确保
t.cardd
也大于0

您可以通过

WHERE t.cardid > 0 OR t.restaurant_id=0 
如果cardid不是必须大于0的,您还可以使用和来确保在PHP中
t.cardid
也大于0

 <?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'];
        }


    ?>

在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'];
        }


    ?>


通过拥有
exp\u频道标题。id为
0
的条目id
?通过拥有
exp\u频道标题。id为
0
的条目id
?当我这样做时,什么都不会出来。甚至连我的餐厅都没有。当我这样做的时候,什么都不会出来。甚至连我的餐厅都没有。当我这样做的时候,什么都不会出来。甚至连我的餐厅都没有。当我这样做的时候,什么都不会出来。甚至连我的餐厅都没有。当我这样做的时候,什么都不会出来。甚至连我的餐厅都没有。当我这样做的时候,什么都不会出来。甚至连我的餐厅都没有_id>0