我需要在一张桌子上安排一些奇怪的条件
我的表是:
| ref | value1 | info1 | value2 | info2 | value3 | info3 |
| 9 | 100 | test1 | 220 | test4 | 300 | test7 |
| 3 | 150 | test2 | 250 | test5 | 400 | test8 |
| 7 | 200 | test3 | 290 | test6 | 500 | test9 |
我需要能够获得如下结果:
| ref | values | infos |
| 9 | 100 | test1 |
| 3 | 150 | test2 |
| 7 | 200 | test3 |
| 9 | 220 | test4 |
| 3 | 250 | test5 |
| 7 | 290 | test6 |
| 9 | 300 | test7 |
| 3 | 400 | test8 |
| 7 | 500 | test9 |
我甚至无法开始明白我的需要是否可能而且我无法理解它。任何帮助将非常感谢。
答案 0 :(得分:2)
您可以使用UNION ALL
SELECT ref, value1 as values, info1 as Infos FROM tbl
UNION ALL
SELECT ref, value2 as values, info2 as Infos FROM tbl
UNION ALL
SELECT ref, value3 as values, info3 as Infos FROM tbl