本文介绍了从同一表中列出mysql中的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何从此表中列出iduser,其中gender = man和int = woman?
How can i list the iduser from this table where gender=man and int=woman?
Table usermeta
----------------------
id iduser a b
12 204 age 19
7 203 age 35
6 200 age 24
3 201 age 34
5 201 gender man
2 200 gender woman
8 203 gender man
9 204 gender man
4 201 int woman
10 204 int male
11 203 int woman
1 200 int male
答案应该是:
iduser
204
我还有一个问题,如果我也想过滤年龄怎么办?我正在尝试解决此问题,但我不能...我应该在哪里放年龄= 19"?我试试这个...a
='年龄'AND a.b
='19'但是不工作...谢谢.
I have another question, what if i want filter the age too?I'am trying to resolve this but i can't...Where shopuld i put the "age=19"?I try this...a.a
= 'age'AND a.b
= '19'but dont work...thanks.
推荐答案
自连接应该起作用.有点像(未经测试的):
A self join should work. Someting like (untested):
SELECT a.`iduser` FROM `table` a
JOIN `table` b ON b.`iduser` = a.`iduser`
WHERE a.`a`='gender' AND a.`b`='man' AND b.`a`='int' AND b.`b`='woman'
但是您应该考虑优化db结构,因为这似乎有点性能不足.
But you should consider to optimize the db structure since this seems a little performace hungry.
这篇关于从同一表中列出mysql中的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!