- Checking users options from default
- user_id | song_id| points
- --------|----------------
- 2 | 1 | 0
- 2 | 2 | 1
- 2 | 3 | 2
- 2 | 4 | 3
- 2 | 5 | 4
- while ($row = mysql_fetch_array($query)) {
- $userID = $row['user_id'];
- $songID = $row['song_id'];
- $points = $row['points'];
- if($songID-$points==1){
- echo $userID."<br>";
- }
- SELECT DISTINCT user_id WHERE (song_id - points) = 1
- SELECT DISTINCT user_id FROM table
- WHERE (song_id - points) != 1
- SELECT DISTINCT user_id FROM table
- WHERE user_id NOT IN (
- SELECT DISTINCT user_id FROM table
- WHERE (song_id - points) != 1
- )
- SELECT DISTINCT user_id FROM table WHERE (song_id - points) = 1
- SELECT table.user_id
- FROM table
- LEFT JOIN (
- SELECT user_id, COUNT(*) AS C FROM table) AS T2
- ON table.user_id = T2.user_id
- WHERE (table.song_id - table.points) = 1
- GROUP BY table.user_id
- HAVING COUNT(*) = T2.C
- select user_id from (
- select user_id, if(song_id - points = 1, 0, 1) flag from t
- ) as S
- group by user_id
- having sum(flag) = 0
- select distinct t1.user_id from t t1
- where not exists (
- select * from t t2
- where t2.song_id - t2.points != 1 and t1.user_id = t2.user_id
- )
- $old_id = '';
- $good = false;
- while($row = mysql_fetch_array($query)){
- //check to see if we have a new user ...
- if($row['user_id'] != $old_id){
- //check to see if all values were == 1
- if($good){
- echo $old_id . '<br />';
- }
- //re-initialize variables
- $good = true;
- $old_id = $row['user_id'];
- }
- //if value != 1, we won't print the user ...
- if($row['song_id'] - $row['points'] != 1){
- $good = false;
- }
- }
- //final end-of-loop condition ...
- if($good){
- echo $old_id . '<br />';
- }
- SELECT user_id, sum(song_id) as song_total, sum(points) as point_total, count(*) AS cnt FROM table GROUP BY user_id
- while($row = mysql_fetch_array($query)){
- if($row['cnt'] == ($row['song_total'] - $row['point_total'])){
- echo $row['user_id'] . '<br />';
- }
- }