MYSQL,如何获取ID大于4的数据

时间:2014-08-23 09:04:31

标签: mysql

Halloprogrammer朋友!

我有一张桌子,名为" testtabel" 内容和形式如下

|ID | DATA1        | DATA2 |
| 1 | hallo        | iya   |
| 2 | iya          | hallo |
| 3 | hallo        | iya   |
| 4 | iya          | hallo |
| 5 | iya          | hallo |
| 6 | hallo        | iya   |
| 7 | apa          | hallo |
| 8 | nama         | dari  |
| 9 | iya          | hallo |

我想显示两个并发数据,其中ID大于4,DATA1 = hallo,DATA2 = iya,DATA1 = iya,DATA2 = hallo 所以结果

| 5 | iya         | hallo    |
| 6 | hallo     | iya        |
| 9 | iya         | hallo    |

请帮助,谢谢

3 个答案:

答案 0 :(得分:1)

只是另一种解决方案:

SELECT *
FROM testtabel
WHERE id > 4
AND ("hallo" in (data1, data2) AND "iya" in (data1, data2) )

答案 1 :(得分:0)

SELECT ID, DATA1, DATA2 FROM testtabel WHERE ID > 4 
AND ((DATA1 = 'hallo' AND DATA2 = 'iya') OR (DATA1 = 'iya' AND DATA2 = 'hallo'))

请查看MySQL Documentation了解详情。

希望这有帮助。

答案 2 :(得分:0)

SELECT *
FROM testtabel
WHERE id > 4
AND ((data1 = 'iya' AND data2 = 'hallo') OR (data1 = 'hallo' AND data2 = 'iya'))