【问题标题】:Mysql condition not workingMysql条件不起作用
【发布时间】:2013-12-09 06:31:43
【问题描述】:

这是我获取特定日期订单总额的查询。在这里,使用 AND (tos.status!='5' 或 tos.status!='6') 时我无法得到正确的结果。这有什么问题?

SELECT sum(tot.total) as total 
FROM orders_totals tot, orders tos 
WHERE DATE(tos.`timestamp`) BETWEEN '2013-12-09' AND '2013-12-09' and 
      tot.`order` = tos.id and tot.description='Grand-Total' AND 
     (tos.status!='5' or tos.status!='6')

【问题讨论】:

  • (tos.status!='5' or tos.status!='6') 总是正确的。因为不是 5 也不是 6。条件应该怎么办?
  • 如果我给 AND tos.status!='6',它显示正确的结果
  • 告诉我们您的具体情况以及您在查询中所说的具体内容?
  • @Prakash - 请添加该评论作为答案。

标签: mysql sql select where notin


【解决方案1】:

试试这个:

SELECT sum(tot.total) as total 
FROM orders_totals tot
INNER JOIN orders tos ON tot.`order` = tos.id
WHERE DATE(tos.`timestamp`) BETWEEN '2013-12-09' AND '2013-12-09' and 
      tot.description='Grand-Total' AND tos.status NOT IN (5, 6)

【讨论】:

    猜你喜欢
    • 2018-08-03
    • 1970-01-01
    • 2015-11-06
    • 1970-01-01
    • 2020-06-15
    • 2020-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多