简体   繁体   English

在其中使用NOT的MySQL查询,可能吗?

[英]MySQL Query using NOT in it, possible?

I have a database of order status' and I'd like to return the amount of rows for which the value of that row is anything but Complete. 我有一个订单状态数据库”,我想返回该行的值不等于“完成”的行数。

How would I go about this? 我将如何处理? I have the following which shows how much rows has 'New' as the status for the order. 我有以下内容显示了多少行具有“新建”作为订单状态。 But I'd like to show all rows except ones with the od_status of Complete. 但是我想显示所有具有od_status为Complete的行。

<?php
$query = "SELECT od_status FROM tbl_order WHERE od_status = 'New'"; 
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
echo "$num_rows";
?>
<?php
$query = "SELECT od_status FROM tbl_order WHERE od_status != 'Complete'"; 
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
echo "$num_rows";
?>
$query = "SELECT od_status FROM tbl_order WHERE od_status <> 'Complete'"; 
$query = "SELECT COUNT(*) FROM tbl_order WHERE od_status != 'Complete'";
$result = mysql_query($query);
var_dump($result);

COUNT to count rows and != to select where is not equal to Complete. 使用COUNT计数行,用!=选择不等于完成位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM