Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 10,11,12,13,3谢谢!工作几乎完美无缺,但如果表几乎满了,它只返回2个审阅者,而不是3个!我认为这是因为你的代码认为:如果A评论B,那么B评论A,但这不是它应该如何工作的!更多的帮助将不胜感激:)我所做的是,如果需要3次审查,并且1人已经审查了该_Mysql_Sql - Fatal编程技术网

Mysql 10,11,12,13,3谢谢!工作几乎完美无缺,但如果表几乎满了,它只返回2个审阅者,而不是3个!我认为这是因为你的代码认为:如果A评论B,那么B评论A,但这不是它应该如何工作的!更多的帮助将不胜感激:)我所做的是,如果需要3次审查,并且1人已经审查了该

Mysql 10,11,12,13,3谢谢!工作几乎完美无缺,但如果表几乎满了,它只返回2个审阅者,而不是3个!我认为这是因为你的代码认为:如果A评论B,那么B评论A,但这不是它应该如何工作的!更多的帮助将不胜感激:)我所做的是,如果需要3次审查,并且1人已经审查了该,mysql,sql,Mysql,Sql,10,11,12,13,3谢谢!工作几乎完美无缺,但如果表几乎满了,它只返回2个审阅者,而不是3个!我认为这是因为你的代码认为:如果A评论B,那么B评论A,但这不是它应该如何工作的!更多的帮助将不胜感激:)我所做的是,如果需要3次审查,并且1人已经审查了该项目,它将随机返回2名审查者。或者,如果2个已经审核,它将返回1个随机审核人。你在寻找什么不同?如果某人A没有被任何人“审阅”,它有时只返回2个人作为A的审阅者。你能描述一下生成该行为的设置吗?是的:审阅(你的脚本已经生成了3条记录)(id,c


10,11,12,13,3谢谢!工作几乎完美无缺,但如果表几乎满了,它只返回2个审阅者,而不是3个!我认为这是因为你的代码认为:如果A评论B,那么B评论A,但这不是它应该如何工作的!更多的帮助将不胜感激:)我所做的是,如果需要3次审查,并且1人已经审查了该项目,它将随机返回2名审查者。或者,如果2个已经审核,它将返回1个随机审核人。你在寻找什么不同?如果某人A没有被任何人“审阅”,它有时只返回2个人作为A的审阅者。你能描述一下生成该行为的设置吗?是的:审阅(你的脚本已经生成了3条记录)(id,code|reviewer):10,3 | 13,3 | 12,3 |用户(id):10,11,12,13,3谢谢!
*--------------------*
| ID | CODE_REVIEWER |
*--------------------*
| 1  |    2          |
| 1  |    3          |
| 1  |    4          |
*--------------------*
*----*
| ID |
*----*
| 1  |
| 2  |
| 3  |
| 4  |
| 5  |
*----*
*-----------*
| REVIEWER  |
*-----------*
|     4     |
|     1     |
|     5     |
*-----------*
*-----------*
| REVIEWER  |
*-----------*
|     1     |
|     5     |
|     3     |
*-----------*
*-----------*
| REVIEWER  |
*-----------*
select newid from (select id, count(*) as num from (select * from users
where id != ?) as users group by id order by RAND() LIMIT ?) as sb
where num < 3 and newid not in (select code_reviewer from reviews where id = ?)
*---*
| 2 |
| 1 |
| 2 |
*---*
declare @userId int
select @userId = 1
declare @existingReviewCount int
select @existingReviewCount = COUNT(*) from Reviews where Id = @userId
declare @requiredRowCount int
select @requiredRowCount = 3 - @existingReviewCount

select top (@requiredRowCount) Id from Users
where @userId != Id
order by NEWID()
select u.*, 
    -- r_counts.cnt as reviews_count,
    substring_index(
        group_concat(u_rev.id order by rand()),
        ',',
        greatest(3-r_counts.cnt,0)) as reviewers
from users u
join users u_rev on u.id != u_rev.id
left join (
    select u.id, count(r.id) as cnt
    from users u
    left join reviews r on u.id = r.id
    group by u.id
) r_counts on r_counts.id = u.id
left join (
    select u.id, count(r.id) as cnt
    from users u
    left join reviews r on u.id = r.reviewer
    group by u.id, r.reviewer
) as did_review_counts
on did_review_counts.id = u_rev.id
where u.id = 11
and did_review_counts.cnt < 3
group by u.id;