在MySQL中选择多个共享最小(PRICE)值的书名?
为此,请使用MySQLMIN()
。让我们首先创建一个-
mysql> create table DemoTable1414 -> ( -> BookTitle varchar(40), -> BookPrice int -> );
使用insert在表中插入一些记录-
mysql> insert into DemoTable1414 values('Deep dive using java',560); mysql> insert into DemoTable1414 values('C++ in depth',360); mysql> insert into DemoTable1414 values('Data structure in C',590); mysql> insert into DemoTable1414 values('Algorithm in C++',1090); mysql> insert into DemoTable1414 values('Java in Depth',360);
使用选择显示表中的所有记录-
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)