+----+-----------+-------------+--------------+------------+
| id | nama_user | kode_cabang | kode_wilayah | kode_jalan |
+----+-----------+-------------+--------------+-------------+
| 1 | jon | 01 | 03 | 01 |
| 2 | jin | 01 | 03 | 01 |
| 3 | jun | 01 | 03 | 04 |
| 4 | siz | 01 | 03 | 02 |
| 5 | suz | 01 | 03 | 03 |
+----+-----------+-------------+--------------+-------------+
我有上面的数据库,我想在jon,jin,siz,suz
字段中返回nama_user
值
我的意思是我如何从mytable中选择kode_cabang = 01和kode_wilayah = 03以及kode_jalan = 01,02,03
答案 0 :(得分:0)
您需要使用IN运算符,如:
... WHERE ... AND kode_jalan IN ('01', '02, '03');
答案 1 :(得分:0)
使用IN
select nama_user from table_name where kode_cabang = 01 and kode_wilayah = 03
and kode_jalan IN (01,02,03)
答案 2 :(得分:0)
您可以使用or
运算符
select nama_user from table_name where kode_cabang = 01 and ode_wilayah = 03 and (kode_jalan = 01 or kode_jalan = 02 or kode_jalan = 03)
答案 3 :(得分:0)
您可以使用GROUP_CONCAT
获取一列中的值
如下所示
select GROUP_CONCAT(nama_user) as nama_user from table_name
where kode_cabang = 01 and kode_wilayah = 03 and kode_jalan IN (01,02,03)
它将以逗号返回单行concat名称。
答案 4 :(得分:0)
select GROUP_CONCAT(nama_user) as nama_user
from table_name
where kode_cabang = "01"
and kode_wilayah = "03"
and (kode_jalan="01" or kode_jalan="02" or kode_jalan="03")
答案 5 :(得分:-1)
使用
SELECT nama_user FROM table_name;