0

我有下面的代码定义的表

CREATE TABLE Products
(
P_Id INTEGER PRIMARY KEY,
name TEXT,
price REAL,
sellPrice REAL,
plu INTEGER,
codeBar TEXT,
tax INTEGER,
amount INTEGER,
date TEXT
);

当我尝试执行这样的查询时,我得到一个语法错误(这是一个准备好的语句)

select * 
from Products 
where P_Id = min(select P_Id from Products where codeBar=?);

有人可以帮忙吗?这个查询有什么问题?

我得到的确切错误消息是:

java.sql.SQLException:靠近“选择”:语法错误

谢谢帮助。

4

2 回答 2

5

MIN()应该在子查询中。

select * 
from Products 
where P_Id = (select min(P_ID) from Products where codeBar=?);
于 2013-01-11T05:42:41.247 回答
1

我相信你想要的是这样的:

select * from Products 
where P_Id = (select min(P_Id) from Products where codeBar=?);
于 2013-01-11T05:41:58.523 回答