2013-02-20 49 views
0

我有一个关于SQL语句的问题。我如何在我的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 
+2

通过使用ID为'0的'exp_channel_titles.entry_id'? – h2ooooooo 2013-02-20 10:35:07

回答

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 
+0

当我这样做时,什么都没有出来。甚至没有我的restaurant_id> 0 – Zaz 2013-02-20 10:44:14

1

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

2

你可以做到这一点通过

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

如果CardId中比0刨丝器不是强制性的,你也可以使用,并确保该t.cardid也大于0

+0

当我这样做时,什么都没有出来。甚至没有我的restaurant_id> 0 – Zaz 2013-02-20 10:44:36

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


    ?> 
+0

当我这样做时,什么都没有出来。甚至没有我的restaurant_id> 0 – Zaz 2013-02-20 10:44:56