如果我理解正確的話,你正在尋找一個店鋪相關的所有忠誠編號的數字,所以一個方法可以把行數據列第一使用union all
,然後尋找一個店;可以說AB
。
select * from
(
select customername, shop1 as shop, shop1number as shopnumber
from table1
union all
select customername, shop2 as shop, shop2number as shopnumber
from table1
union all
select customername, shop3 as shop, shop3number as shopnumber
from table1
) t
where t.shop = 'AB';
結果:
+--------------+------+------------+
| customername | shop | shopnumber |
+--------------+------+------------+
| AMY | AB | 213 |
| TOM | AB | 111 |
| Franck | AB | 234 |
+--------------+------+------------+
DEMO
請您可以使表格設計更清晰一點?也許提供一張圖片? – majjam
這是3排嗎? '店1/AAA /店鋪2/BBB /店鋪3/CCC'或在同一行上的單個列? –
沒有那是一排有6列,因此該表看起來像 –