我有三张桌子:
苹果
ID | APPLE
----------
1 | RED
2 | YELLOW
3 | GREEN
ID | FARM
--------------------
B1 | GEORGE'S FARM
B2 | JOHN'S FARM
农场苹果
FARM | APPLE
---------------
B1 | 1
B1 | 2
B1 | 3
B2 | 1
B3 | 3
有了这些表,我需要这个结果:
FARM_NAME | APPLE_1 | APPLE_2 | APPLE_3
----------------------------------------
B1 | 1 | 2 | 3
B2 |1 | | 3
如有任何帮助,我们将不胜感激。
编辑
感谢OMG Ponies和Bill,我将尝试您的两种解决方案,最后一件事,可能会得到以下结果:
FARM | RED | YELLOW | GREEN
-------------------------------------
GEORGE'S FARM | YES | YES | YES
JOHN's FARM | YES | NO | YES