以下のクエリは、null の列名を返すために正常に機能します。私が達成しようとしているのは、null 値を持つ最初の列名に戻すことです。各行に一意の電子メール アドレスを持つ、email という名前の別の列もあります。私の問題は、これを行うための適切な構文を理解できないことです。どんな助けでも大歓迎です!
これにはphp5.2も使用しています。
SELECT col FROM (SELECT 'GAME0' AS col, GAME0 AS value FROM USERNAME
UNION ALL SELECT 'GAME1', GAME1 FROM USERNAME
UNION ALL SELECT 'GAME2', GAME2 FROM USERNAME
UNION ALL SELECT 'GAME3', GAME3 FROM USERNAME
UNION ALL SELECT 'GAME4', GAME4 FROM USERNAME
UNION ALL SELECT 'GAME5', GAME5 FROM USERNAME
UNION ALL SELECT 'GAME6', GAME6 FROM USERNAME
UNION ALL SELECT 'GAME7', GAME7 FROM USERNAME
UNION ALL SELECT 'GAME8', GAME8 FROM USERNAME
UNION ALL SELECT 'GAME9', GAME9 FROM USERNAME
UNION ALL SELECT 'GAME10', GAME10 FROM USERNAME
UNION ALL SELECT 'GAME11', GAME11 FROM USERNAME
UNION ALL SELECT 'GAME12', GAME12 FROM USERNAME
UNION ALL SELECT 'GAME13', GAME13 FROM USERNAME
UNION ALL SELECT 'GAME14', GAME14 FROM USERNAME
UNION ALL SELECT 'GAME15', GAME15 FROM USERNAME
UNION ALL SELECT 'GAME16', GAME16 FROM USERNAME
UNION ALL SELECT 'GAME17', GAME17 FROM USERNAME
UNION ALL SELECT 'GAME18', GAME18 FROM USERNAME
UNION ALL SELECT 'GAME19', GAME19 FROM USERNAME
) allValues
WHERE value is null and email='emailaddress'
編集: 上記のクエリが不要な場合は、最初の null 値の値を変更できる以下のようなものが必要です。繰り返しますが、構文は私の最大の問題です。
update username
SET CASE GAME0
WHEN GAME0 IS NOT NULL THEN GAME1
WHEN GAME1 IS NOT NULL THEN GAME2
WHEN GAME2 IS NOT NULL THEN GAME3
WHEN GAME3 IS NOT NULL THEN GAME4
WHEN GAME4 IS NOT NULL THEN GAME5
WHEN GAME5 IS NOT NULL THEN GAME6
WHEN GAME7 IS NOT NULL THEN GAME8
WHEN GAME8 IS NOT NULL THEN GAME9
WHEN GAME9 IS NOT NULL THEN GAME10
WHEN GAME10 IS NOT NULL THEN GAME11
WHEN GAME11 IS NOT NULL THEN GAME12
WHEN GAME12 IS NOT NULL THEN GAME13
WHEN GAME13 IS NOT NULL THEN GAME14
WHEN GAME14 IS NOT NULL THEN GAME15
WHEN GAME15 IS NOT NULL THEN GAME16
WHEN GAME16 IS NOT NULL THEN GAME17
WHEN GAME17 IS NOT NULL THEN GAME18
WHEN GAME18 IS NOT NULL THEN GAME19
END where EMAIL='emailaddress'