0

我有两个表:
client:(backoffice_users_id,idfile,validation_file)
transmission:(backoffice_users_id,idfile,nbr_files)

我想向具有最少文件数且validation_file=1的客户展示

我做了这样的事情,它给了我最小数量但是validation_file = 0而不是validation_file = 1,有人可以帮我吗?

SELECT `transmission`.* 
FROM `transmission`
INNER JOIN `client`
ON client.backoffice_users_id=transmission.backoffice_users_id 
WHERE (transmission.idfile='2') 
  AND (client.validation_file<>0) 
  AND (transmission.nbr_files=(
         SELECT min(nbr_files) 
         FROM transmission 
         WHERE transmission.idfile='2')) 
GROUP BY `client`.`backoffice_users_id`
LIMIT 1 
4

1 回答 1

0

我不知道你的transmission.idfile='2'意思是什么,所以只回答'最小文件数量和validation_file = 1'-part以及一次传输中的文件数量最少(不是多次传输的总和):

SELECT * FROM `transmission`
INNER JOIN `client` ON 
    `client`.`backoffice_users_id` = `transmission`.`backoffice_users_id` AND
    `client`.`validation_file` = 1
ORDER BY `transmission`.`nbr_files` ASC
LIMIT 1
于 2013-11-10T14:10:32.853 回答