У меня есть три логических столбца в таблице, которые определяют, какие значения должны быть переданы в программу.Мне нужно передать до 3 меток и значений в мою программу.
На данный момент у меня есть 8 случаев для каждой метки и каждого значения (так как 3 логических флага означают 2 ^ 3 = 8 комбинаций).Есть ли способ сделать его более лаконичным?
Например, для моего первого ярлыка у меня есть
case
WHEN travelExpenseEnabled=0 and otherExpenseEnabled=0 and materialExpenseEnabled = 0 THEN
''
WHEN travelExpenseEnabled=1 and otherExpenseEnabled=0 and materialExpenseEnabled = 0 THEN
'Estimated Travel Expense'
WHEN travelExpenseEnabled=1 and otherExpenseEnabled=1 and materialExpenseEnabled = 0 THEN
'Estimated Travel Expense'
WHEN travelExpenseEnabled=1 and otherExpenseEnabled=0 and materialExpenseEnabled = 1 THEN
'Estimated Material'
WHEN travelExpenseEnabled=1 and otherExpenseEnabled=1 and materialExpenseEnabled = 1 THEN
'Estimated Material'
WHEN travelExpenseEnabled=0 and otherExpenseEnabled=1 and materialExpenseEnabled = 0 THEN
CONCAT('Estimated ', listquotes.otherLabel)
WHEN travelExpenseEnabled=0 and otherExpenseEnabled=1 and materialExpenseEnabled = 1 THEN
'Estimated Material'
WHEN travelExpenseEnabled=0 and otherExpenseEnabled=0 and materialExpenseEnabled = 1 THEN
'Estimated Material'
END as optLabel1,
И аналогично для первого значения.Этот метод также означает, что мне нужно, чтобы моя собственная иерархия материалов> путешествия> другие согласовывалась для каждой другой части моего запроса, поэтому это быстро станет головной болью, если меня попросят изменить порядок.Возможно ли вместо этого сделать что-то вроде следующего
case
WHEN travelExpenseEnabled=0 and otherExpenseEnabled=0 and materialExpenseEnabled = 0 THEN
'' as optLabel1,
'' as optLabel2,
'' as optLabel3,
0.00 as estCost1,
0.00 as estCost2,
0.00 as estCost3,
WHEN travelExpenseEnabled=1 and otherExpenseEnabled=0 and materialExpenseEnabled = 0 THEN
'Estimated Travel' as optLabel1,
'' as optLabel2,
'' as optLabel3,
travelExpense as estCost1,
0.00 as estCost2,
0.00 as estCost3
и т. Д. Для каждого случая.Таким образом, я могу установить каждое из 3-х значений, которые мне нужно, всего в 8 случаях, вместо того, чтобы делать 8 случаев на одно значение.Это возможно?Я использую MySQL 5.6