我有两个表:
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

最佳答案

我不知道您的transmission.idfile='2'是什么意思,所以只回答“最小文件数,validation_file = 1”部分,并且一次传输中的文件数最少(不对多次传输求和):

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

关于mysql - 在SQL查询中显示具有最小数量的客户端,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19890404/

10-10 06:49