codeigniter 请求sql代码触发器

dbf7pr2w  于 2023-02-27  发布在  其他
关注(0)|答案(1)|浏览(117)

我卡住了我想用codeigniter函数执行sql查询,但我不能

SELECT Players.Pseudo as Pseudo, 
       COUNT(CASE WHEN Games.Gagnant = Players.IdPlayer THEN 1 END) AS Victoires, 
       COUNT(CASE WHEN Games.Gagnant != Players.IdPlayer THEN 1 END) AS Defaites
, 
       ROUND(COUNT(CASE WHEN Games.Gagnant = Players.IdPlayer THEN 1 END)/COUNT(CASE WHEN Games.Gagnant != Players.IdPlayer THEN 1 END),2) AS Ratio 
FROM Players
LEFT JOIN Games ON Players.IdPlayer = Games.IdJoueur1 OR Players.IdPlayer = Games.IdJoueur2;

我试过了,但是没用...

$builder=$this->db->table('Players');
$recherche = $_POST['recherche'];
$where = "Players.Pseudo = $recherche AND Players.IdPlayer = Games.IdJoueur1 OR Players.IdPlayer = Games.IdJoueur2";
$join = $builder->join('Games', $where);
$table = $join->get();
$query = $table->select('Players.Pseudo as Pseudo, COUNT(CASE WHEN Games.Gagnant = Players.IdPlayer THEN 1 END) AS Victoires, COUNT(CASE WHEN Games.Gagnant != Players.IdPlayer THEN 1 END) AS Defaites
, ROUND(COUNT(CASE WHEN Games.Gagnant = Players.IdPlayer THEN 1 END)/COUNT(CASE WHEN Games.Gagnant != Players.IdPlayer THEN 1 END),2) AS Ratio');
$classement = $query->get()->getResultArray();
btxsgosb

btxsgosb1#

谢谢你的回复!你会看到更多的风格要求?但这也不起作用...

$builder->select('Players.Pseudo as Pseudo, COUNT(CASE WHEN Games.Gagnant = Players.IdPlayer THEN 1 END) AS Victoires, COUNT(CASE WHEN Games.Gagnant != Players.IdPlayer THEN 1 END) AS Defaites 
       , ROUND(COUNT(CASE WHEN Games.Gagnant = Players.IdPlayer THEN 1 END)/COUNT(CASE WHEN Games.Gagnant != Players.IdPlayer THEN 1 END),2) AS Ratio')
       ->from('Players');
       ->join('Games', new RawSql($sql), 'left')
       ->where('Players.Pseudo ',  $_POST["recherche"])
        $recherche = $builder->get()->getResultArray();```

相关问题