在 MySQL 中选择多个共享最小(PRICE)值的图书标题?
为此,使用 MySQL MIN()。我们首先创建 −
mysql> create table DemoTable1414 -> ( -> BookTitle varchar(40), -> BookPrice int -> ); Query OK, 0 rows affected (0.82 sec)
使用 insert 在表中插入一些记录 −
mysql> insert into DemoTable1414 values('Deep dive using java',560); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('C++ in depth',360); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('Data structure in C',590); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('Algorithm in C++',1090); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1414 values('Java in Depth',360); Query OK, 1 row affected (0.33 sec)
使用 select 从表中显示所有记录 −
mysql> select * from DemoTable1414;
将生成以下输出 −
+----------------------+-----------+ | BookTitle | BookPrice | +----------------------+-----------+ | Deep dive using java | 560 | | C++ in depth | 360 | | Data structure in C | 590 | | Algorithm in C++ | 1090 | | Java in Depth | 360 | +----------------------+-----------+ 5 rows in set (0.00 sec)
以下是查询,用于选择共享最小价格值的多个图书标题−
mysql> select BookTitle from DemoTable1414 -> where BookPrice= ( select min(BookPrice) from DemoTable1414);
将生成以下输出 −
+---------------+ | BookTitle | +---------------+ | C++ in depth | | Java in Depth | +---------------+ 2 rows in set (0.00 sec)
广告