我有2张桌子:
TBL_SERVICE:
ID SERVICE_NAME
-- ------------
1 servicea
2 serviceb
3 servicec
TBL_OPTIONS:
ID TYPE VALUE ID_SERVICE
-- ---- ----- ----------
1 AAA X 1
2 BBB Y 1
3 CCC Z 1
4 AAA S 2
5 BBB X 2
6 AAA T 3
现在我需要生成这样的行:
ID_SERVICE TYPE_AAA TYPE_BBB TYPE_CCC
---------- -------- -------- --------
1 X Y Z
2 S X
3 T
当前,我使用php代码执行此操作,但我需要在sql查询中执行此操作。在mysql中有可能吗?
答案 0 :(得分:1)
您可以使用条件聚合:
In [144]: n = int(input())
3
In [145]: arr = map(int, input().split())
14 23 1
#list_arr can be used for subsequent code, you have consumed arr completely
In [146]: list_arr = list(arr)
In [147]: print(list_arr)
[14, 23, 1]
#Iterator is empty after using it once
In [148]: print(list(arr))
[]