MySQL 许多“和”;声明
我有这样的语句,这是错误的方法,但是我如何让该语句发挥作用(该语句的结果需要包含其中的所有 AND )
SELECT a.username, a.first_name, a.last_name
, b.tx_time, b.account_id
, a.id
, b.table_id, b.tx_type, b.amount
FROM punter a
, account_transaction b
WHERE b.tx_time >= '2011-07-01'
AND b.tx_time < '2011-09-30'
AND b.account_id = a.id
AND b.tx_type = 4
AND b.tx_type = 14
I have this statement which is the wrong way to do it but how would I get the statement to work (the result of the statement needs to hold all the AND in it)
SELECT a.username, a.first_name, a.last_name
, b.tx_time, b.account_id
, a.id
, b.table_id, b.tx_type, b.amount
FROM punter a
, account_transaction b
WHERE b.tx_time >= '2011-07-01'
AND b.tx_time < '2011-09-30'
AND b.account_id = a.id
AND b.tx_type = 4
AND b.tx_type = 14
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
AND b.tx_type = 4 AND b.tx_type = 14
将为您提供空结果集。一列同时只能有一个值。AND b.tx_type = 4 AND b.tx_type = 14
will give you empty result set. One column can only have one value at the same time.您可以使用显式 JOIN 来简化一点:
请注意,我认为使用
b.tx_type = 4 AND b.tx_type = 14
是错误的,因为它始终为 false。如果您需要获取具有tx_type = 4
或tx_type = 14
的记录,您可以更改最后的 SQL 行:You could use explicit JOIN to simplify a bit:
Note that I think it's an error using
b.tx_type = 4 AND b.tx_type = 14
because it's always false. If you need to get records havingtx_type = 4
ortx_type = 14
you can change last SQL lines with我只是猜你的意思是
b.tx_type = 4 OR b.tx_type = 14
I just guess you meant
b.tx_type = 4 OR b.tx_type = 14
这部分:
确保您在结果中获得零行。
如果您希望
下注者
同时进行4
和14
类型的交易,则需要JOIN
两次进入赌桌b:This part:
ensures that you will get zero rows in the result.
If you want to have
punters
with transcations of both type4
and14
, you need toJOIN
twice to tableb
: