通过php将一个表中的一个字段与mysql中的另一个表中的几个字段进行比较

时间:2016-01-08 19:35:46

标签: php mysql

我有这条线

$sql_events = mysql_query("SELECT team FROM weekpicks WHERE whatweek='$totalnoOfWeek'-1 and team in ( SELECT team1 FROM weekslosers WHERE whatweek='$totalnoOfWeek'-1 ) or ( SELECT team2 FROM weekslosers WHERE whatweek='$totalnoOfWeek'-1 ) ORDER BY 'username' asc ")

它有效,但我还需要它来检查team2,team3等等。我以为我可以做类似以下的事情,但它不起作用。它似乎停在team1

if ENV['DB_MIGRATE'] == 'skip'
  Rake::Task["deploy:migrate"].clear_actions
  namespace :deploy do
    desc "Override Capistrano's default behavior, do not migrate on deploy"
    task :migrate do
      puts 'BOO!'
    end
  end
end

或者这应该以不同的方式完成?

我想要做的是从桌上的周训练队中拿出球队并将其与表周的球队进行比较,而周球队表可能有多达8支失败的球队,所以如果你的球队是8支球队之一,我需要它待上市。

1 个答案:

答案 0 :(得分:1)

SELECT team
FROM weekpicks
INNER JOIN weekslosers ON weekpicks.whatweek = weekslosers.whatweek
WHERE weekpicks.whatweek = (whatever) AND team IN (weekslosers.team1, weekslosers.team2)

另外,你应该考虑从mysql_ *转向mysqli或PDO。