如何 select column2 但如果 column2 为零而不是 select column1

How to select column2 but if column2 is zero than select column1

我有以下 woocommerce table (wp_wc_order_product_lookup):

|---------------------|-------------------|
|      product_id     |     variant_id    |
|---------------------|-------------------|
|          23         |         0         |
|          24         |         32        |
|          25         |         34        |
|---------------------|-------------------|

我想做一个 mysql 查询,它给我 product_id。如果 variant_id 比 return 为 0,则 product_id 否则我想得到 variant_id:

|---------------------|
|      product_id     | 
|---------------------|
|          23         |
|          32         |
|          34         |
|---------------------|

使用case表达式:

select case when variant_id = 0 then product_id else variant_id end as product_id
from mytable