SELECT c.* from chart as c,grel as gr where (c.id not in(710,722,723) and c.id=gr.tgtId and gr.srcId = 837 and gr.srcType=1 and gr.tgtType=4);SELECT * from chart as c where c.id in(710,722,723);怎么用or变成一条语句啊,求大神

解决方案 »

  1.   

    select c.* from chart as c,grel as gr
    where c.id=gr.tgtid and gr.srcid=837 and gr.srcType=1 and gr.tgtType=4
    and c.id not in(710,722,723)or c.id in(710,722,723);
      

  2.   

    select c.* from chart as c,grel as gr
    where c.id=gr.tgtid and gr.srcid=837 and gr.srcType=1 and gr.tgtType=4
    and (c.id not in(710,722,723)or c.id in(710,722,723));
      

  3.   

    用UNION不行么?
    SELECT c.* 
    FROM chart AS c,grel AS gr 
    WHERE (c.id NOT IN(710,722,723) AND c.id=gr.tgtId AND gr.srcId = 837 AND gr.srcType=1 AND gr.tgtType=4)
    UNION ALL 
    SELECT * FROM chart AS c WHERE c.id IN(710,722,723);
      

  4.   

    是自己封装的hibernate啊,union用不了
      

  5.   

    用union数据列数必须是相同的。
      

  6.   

    用union必须数据类型和列数都是相同的才可以的。
      

  7.   

    是相同的啊,但是自己封装的hibernate没有加执行sql的那个方法,union现在不能用了,你上面帮我写的那个取出来少了
      

  8.   

    应该不是这个问题,他都是查询的chart.*。
      

  9.   

    你这两个表的结果是怎么的,grel表的tgtId是否有重复情况?
      

  10.   

    试试这个呢?SELECT c.* 
    FROM chart AS c,grel AS gr 
    WHERE (c.id NOT IN(710,722,723) AND c.id=gr.tgtId AND gr.srcId = 837 AND gr.srcType=1 AND gr.tgtType=4)
    OR (c.id IN(710,722,723) AND gr.主键=任意一个grel表的主键);
      

  11.   

    SELECT c.* from chart as c,grel as gr where (c.id not in(710,722,723) and c.id=gr.tgtId and gr.srcId = 837 and gr.srcType=1 and gr.tgtType=4)or
    c.id in(710,722,723);
    orSELECT c.* from chart as c,grel as gr where 
    c.id in(710,722,723)
    or 
    (c.id not in(710,722,723) and c.id=gr.tgtId and gr.srcId = 837 and gr.srcType=1 and gr.tgtType=4)
      

  12.   

    SELECT c.* from chart as c,grel as gr where (c.id not in(710,722,723) and c.id=gr.tgtId and gr.srcId = 837 and gr.srcType=1 and gr.tgtType=4) or c.id in(710,722,723) group by c.id