1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Sql语句 多个字段模糊查询

Sql语句 多个字段模糊查询

时间:2018-12-17 00:16:47

相关推荐

Sql语句 多个字段模糊查询

Sql语句收获

1、

select * from 表 order by time asc

最早时间在前

select * from 表 order by time desc

最新时间在前

2、模糊查询

select id, sys_user.user_name as userName,sys_user.nick_name as nickName,score_theme.theme_name as themeName,score_theme.create_time as createTime

from sys_user

inner join score_theme

on sys_user.user_id = score_theme.fk_publish_user

and deleted = 1

**<if test="searchValue !=null and searchValue != ''">and sys_user.user_name like concat('%',#{searchValue},'%')( or sys_user.nick_name like concat('%',#{searchValue},'%') )( or score_theme.theme_name like concat('%',#{searchValue},'%') )</if>**order by score_theme.create_time desc</select>

多个字段模糊查询 concat(’%’,#{searchValue},’%’)

3、mybaties的聚连

<resultMap type="com.gwm.score.domain.vo.ScoreTargetVO" id="ScoreTargetVOResult"><result property="id" column="id" /><result property="targetName" column="targetName" /><collection property="scoreDimensionVOList"select="selectScoreDimensionVoList"column="{targetId=targetId,fkVoter=fkVoter}"ofType="com.gwm.score.domain.vo.ScoreDimensionVO"></collection></resultMap><select id="getScoreTargetVo" resultMap="ScoreTargetVOResult">select target_name as targetName,end_time as endTime,#{fkVoter} as fkVoter,#{targetId} as targetIdfrom score_target,score_themewhere score_target.id=#{targetId}and score_target.fk_theme_id=score_theme.id</select><select id="selectScoreDimensionVoList" resultType="com.gwm.score.domain.vo.ScoreDimensionVO">select score_dimension.id,dimension_name as dimensionName,(select score from score_recordwhere score_record.fk_target_id=#{targetId}and state=1and fk_dimension_id=score_dimension.idand score_record.fk_voter=#{fkVoter}) as scorefrom score_dimensionwhere fk_theme_id=(select fk_theme_id from score_target where id=#{targetId}) and state =1</select>

colum对应的不是数据库里的字段 而是你查出来的字段得名字

注意

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。