选择最大值行 [英] select maximum value row

查看:112
本文介绍了选择最大值行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在数据库表中选择最新的请求.
这意味着我要选择最大请求ID号和相关的行值.

我将sql查询写为

I want to select only the newest request in the database table.
that means i want to select the maximum request ID number and related row values.

I wrote sql query as

select docName,max(appID) as appID 
from Appointment 
where patID='p00000001' 
group by docName;


发生了如下错误.
在需要条件的上下文中在'')''附近指定的非布尔类型的表达式.

任何人都知道一种解决问题的方法.


An error occured as follow.
An expression of non-boolean type specified in a context where a condition is expected, near '')''.

Any one know a method to solve the problem

推荐答案

您的查询看起来还可以,但不会导致最大appid的记录集.

试试

your query looks okay but it will not result the record set of the maximum appid.

try

select *
from Appointment
where appID = (
select max(appID)
from Appointment
where patID='p00000001')




另外,希望patID列是varchar吗?




Also, hope the patID column is varchar ?


这篇关于选择最大值行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆