MySQL许多'和'语句(MySQL many 'and' statements)

系统教程 行业动态 更新时间:2024-06-14 16:58:29
MySQL许多'和'语句(MySQL many 'and' statements)

我有这个说法,这是错误的方法,但我怎么能让语句工作(语句的结果需要保存所有的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 wich 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

最满意答案

AND b.tx_type = 4 AND b.tx_type = 14将为您提供空结果集。 一列只能同时拥有一个值。

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 INNER JOIN account_transaction b ON b.account_id = a.id WHERE b.tx_time BETWEEN '2011-07-01' AND '2011-09-30' AND b.tx_type IN (4,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.

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 INNER JOIN account_transaction b ON b.account_id = a.id WHERE b.tx_time BETWEEN '2011-07-01' AND '2011-09-30' AND b.tx_type IN (4,14)

更多推荐

本文发布于:2023-04-15 03:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/0250335ce9d856d7a8cbd838d1b04b05.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   MySQL   statements

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!