我有两个表存储有关上传到站点调用图像和审核的图像的信息。上传图像时,它的路径存储在 image.imageLocation 中,当它用于审计时,auditID 保存到同一个表中。auditID 是用于将表连接在一起的值。
我正在尝试进行查询,该查询将使用审核的日期(即 audit.dateStart)告诉我使用该图像的最新审核。
到目前为止我的查询是......
SELECT * FROM (
SELECT image.imageID AS newest_image, image.userID AS image_userID,
image.auditID as image_auditID, image.type AS image_type,
image.imageLocation AS location
from image
) image
LEFT JOIN audit ON image_auditID = audit.auditID
WHERE image_userID = '$id' AND image_type = 'standard'
AND dateStart = MAX(dateStart)
GROUP by location
这会引发错误,说明对 GROUP 的使用不当。
任何帮助将不胜感激
这是表结构
audit
auditID varchar(255)
userID int(11)
dateStart date
dateEnd date
auditName varchar
auditDesc varchar
imagesUploaded tinyint
actionPlan varchar
auditComplete tinyint
dateComplete datetime
image
imageID int(10)
name varchar(255)
auditID varchar(255)
imageGrade int(1)
exposure varchar(255)
positioning varchar(255)
patient varchar(255)
equipment varchar(255)
positioningReason varchar(255)
exposureReason varchar(255)
patientReason varchar(255)
comment varchar(255)
auditDate datetime
imageLocation varchar(255)
thumbnail text
xrayType varchar(10)
type varchar(255)
userID int(11)
Some sample data
imageID = 563
name = standard_16.jpg
auditID = 1360318160843025059
imageLocation = upload/2/standards/standard_16.jpg
type = standard
userID = 2
imageID = 565
name = standard_18.jpg
auditID = 1360318160843025059
imageLocation = upload/2/standards/standard_18.jpg
type = standard
userID = 2
imageID = 566
name = standard_18.jpg
auditID = 13603248241777655575
imageLocation = upload/2/standards/standard_18.jpg
type = standard
userID = 2
auditID = 1360318160843025059
userID = 2
dateStart = 2013-02-14
auditID = 13603248241777655575
userID = 2
dateStart = 2013-02-09
如您所见,相同的图像可用于多个审核,我想知道哪个审核最后使用了该图像,在这种情况下,结果将是 auditID 1360318160843025059