橙稚
2017-06-28 02:31
采纳率: 63.5%
浏览 5.1k

SQL模糊查询语句问题,一个查询结果是另一个的模糊查询条件

SELECT ROUND(AVG(CESHICHENGJI),2) AS pjcj FROM t_datacenter WHERE CESHIXIANGMUMINGCHENG = 身高 AND t_datacenter.JIGOUDAIMA LIKE (SELECT t_department.CODE FROM t_department WHERE t_department.NAME = '通州区') AND SUBSTRING(CESHIRIQI,1,4) =2017

怎么写啊?代码大概就是这样

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • x_mario 2017-06-28 02:51
    已采纳
      SELECT
    ROUND(AVG(CESHICHENGJI),2) AS pjcj 
    FROM t_datacenter 
    WHERE 
    CESHIXIANGMUMINGCHENG = 身高 
    AND t_datacenter.JIGOUDAIMA LIKE  concat('%',(SELECT t_department.CODE FROM t_department WHERE t_department.NAME = '通州区'),'%' )
    AND SUBSTRING(CESHIRIQI,1,4) =2017
    
    点赞 评论
  • x_mario 2017-06-28 02:35

    in like 换成in,你的子查询应该会查回很多条数据 所以要用in

    点赞 评论
  • x_mario 2017-06-28 02:48

    这个是mysql或者sql server的查询方式,上面那个是oracle或者db2的查询方式

     SELECT
    ROUND(AVG(CESHICHENGJI),2) AS pjcj 
    FROM t_datacenter 
    WHERE 
    CESHIXIANGMUMINGCHENG = 身高 
    AND t_datacenter.JIGOUDAIMA LIKE like concat('%',(SELECT t_department.CODE FROM t_department WHERE t_department.NAME = '通州区'),%' )
    AND SUBSTRING(CESHIRIQI,1,4) =2017
    
    点赞 评论

相关推荐 更多相似问题