SQL返回基于2个因子的行(Oracle / JPA)

时间:2015-08-31 19:20:52

标签: sql

假设用户选择了40的fkey。我想返回与col1,col2组合匹配的行。

    Table 1

id       col1     col2     fkey
---      ----     ---    ----
1        A         E      10
2        A         E      20
3        A         E      40
4        B         W      50
5        B         W      99
6        C         E      12
7        C         E      43

结果:

id       col1     col2     fkey
---      ----     ---    ----
1        A         E      10
2        A         E      20
3        A         E      40

2 个答案:

答案 0 :(得分:1)

这是你想要的吗?

public function actionAdmin()
{ 
        $model=new Student('search');
        $model->unsetAttributes();
        $y=date('Y');
        $y1=date('Y',strtotime($y.'+1 year'));
        $test=$y.'-'.$y1;    

        if (isset($_GET['Student']['year'])){
            $model->year=$_GET['Student']['year'];

        }
        if (isset($_GET['Student']['filter'])){
            $model->filter=$_GET['Student']['filter'];
        } 

        if(isset($_GET['Student'])){
                $model->attributes=$_GET['Student'];
        } else{
            //for custom & ajax filters to work together
            $model->year=$test;
            $model->filter='A';
        }
        $this->render('admin',array(
                'model'=>$model,
        ));

答案 1 :(得分:1)

SEL * 
FROM table1
WHERE (col1,col2) 
IN (SEL col1, col2 
    FROM table1 
    WHERE fkey = 40)
ORDER BY fkey
;