Mysql数据透视表同时检查同一列的两个值

时间:2014-12-14 07:57:21

标签: mysql pivot case where

我有以下结构的数据透视表:

|  keyx  |  value |  name  |  id  |  form_no  |
-----------------------------------------------
| hour   |   01   |  Ali   |   12 | 100000001 |
-----------------------------------------------
| min    |   00   |  Ahmad |   17 | 100000001 |
-----------------------------------------------
| hour1  |   03   | John   |   21 | 100000001 |
-----------------------------------------------
| min1   |   01   | Mike   |   33 | 100000001 |
-----------------------------------------------
| hour   |   01   | Homa   |  76  | 100000002 |
-----------------------------------------------
| min    |   02   | Omid   |  73  | 100000002 |

现在我想从表格(my_table)中选择name,id,form_no,但请检查keyx = 'hour' and value = '01' and keyx = 'min' AND value = 'oo' and form_no = '100000001'是否正确。因此,我可以使用WHERE CASEWHERE IF。感谢您的指导和帮助。

1 个答案:

答案 0 :(得分:0)

试试这样: -

select name,id,form_no from table(my_table) where keyx in ('hour','min') and value in (01,00) and form_no= 100000001;