单个表的 SELECT 语句 / 创建比较条件 |
下列查询中的语句说明如何在 WHERE 子句中使用单字符通配符。而且,它们还演示了如何查询非当前数据库中的表。stock 表位于数据库 sloth 中。除了在当前演示数据库外部之外,sloth 还在称为 meerkat 的独立数据库服务器上。
图: 查询
SELECT stock_num, manu_code, description, unit_price FROM sloth@meerkat:stock WHERE manu_code LIKE '_R_' AND unit_price >= 100 ORDER BY description, unit_price; SELECT stock_num, manu_code, description, unit_price FROM sloth@meerkat:stock WHERE manu_code MATCHES '?R?' AND unit_price >= 100 ORDER BY description, unit_price;
图: 查询结果
stock_num manu_code description unit_price 205 HRO 3 golf balls $312.00 2 HRO baseball $126.00 1 HRO baseball gloves $250.00 7 HRO basketball $600.00 102 PRC bicycle brakes $480.00 114 PRC bicycle gloves $120.00 4 HRO football $480.00 110 PRC helmet $236.00 110 HRO helmet $260.00 307 PRC infant jogger $250.00 306 PRC tandem adapter $160.00 308 PRC twin jogger $280.00 304 HRO watch $280.00