Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何筛选列以选择特定关键字_Mysql_Sql_Database - Fatal编程技术网

Mysql 如何筛选列以选择特定关键字

Mysql 如何筛选列以选择特定关键字,mysql,sql,database,Mysql,Sql,Database,我有一个名为Products的表,其中有一列名为product and airport。 机场有多种价值 我需要一个SQL语句,通过该语句,我可以从airport列(具有多个值,如伯明翰国际机场、卢顿机场、希思罗机场、盖特威克机场)中获取一个机场的产品名称 e、 如果我想要机场希思罗机场的所有产品,我会怎么做? 我会使用索引吗?如果是,如何使用? 以下是示例数据: mysql> SELECT * FROM products order by product; | id | product

我有一个名为Products的表,其中有一列名为product and airport。 机场有多种价值 我需要一个SQL语句,通过该语句,我可以从airport列(具有多个值,如伯明翰国际机场、卢顿机场、希思罗机场、盖特威克机场)中获取一个机场的产品名称 e、 如果我想要机场希思罗机场的所有产品,我会怎么做? 我会使用索引吗?如果是,如何使用? 以下是示例数据:

mysql> SELECT * FROM products order by product;

| id | product                          | price  | description                    | type    | airport                                                    |
|  1 | Benson and Hedges Special filter | £28.00 | Cigarettes, Lighter and filter | Tobacco | Birmingham International, Luton Airport, Heathrow, Gatwick |
-----------------------
1 row in set (0.00 sec)
结构变化 我建议您以这种方式创建其他表:

Product (id, product, price, description)
ProductAirports (productId, airportId)
Airport (id, name)
询问 然后,如果你想在伯明翰国际机场买到这些产品,你可以写信

select 
    p.id, p.product
from Product p
    inner join ProductAirports pa on pa.productId = p.id
    inner join Airport a on a.id = pa.airportId
where
    a.name = 'Birmingham International'

为机场创建新表,f.e

CREATE TABLE "AIRPORT"
  (
    "AIRPORT_ID"    NUMBER ,
    "AIRPORT_NAME"   CHAR
)
并通过链接表将您的表与机场链接

CREATE TABLE "CITS_USER"."L_YOUR_TABLE_AIRPORT"
  (
    "L_YOUR_TABLE_AIRPORT_ID" NUMBER NOT NULL ENABLE,
    "YOUR_TABLE_ID"          NUMBER NOT NULL ENABLE,
    "AIRPORT_ID"       NUMBER NOT NULL ENABLE
    CONSTRAINT "FK_L_YOUR_TABLE_AIRPORT_YOUR_TABLE" FOREIGN KEY ("YOUR_TABLE_ID") REFERENCES "YOUR_TABLE" ("YOUR_TABLE_ID") ENABLE,
    CONSTRAINT "FK_L_L_YOUR_TABLE_AIRPORT_AIRPORT" FOREIGN KEY ("AIRPORT_ID") REFERENCES "AIRPORT" ("AIRPORT_ID") ENABLE
  )
因此,您的查询将是

select yt.product from 
your_table yt
join L_YOUR_TABLE_AIRPORT yta on yta.YOUR_TABLE_ID = yt.YOUR_TABLE_ID
join AIRPORT ap on ap.AIRPORT_ID = yta.AIRPORT_ID
where ap.NAME = 'Luton Airport'

一些示例数据和预期输出将有助于澄清您的问题。您是否可以添加相同的示例输出和表值?在这里,我需要类似于select product where airport=“伯明翰”的内容