李振海的gravatar头像
李振海 2017-12-10 10:20:58

mybatis sql复杂查询问题

  <select id="selectByWeishangqiangIdInOrderCreateTimeAsc" resultMap="BaseResultMap">

      SELECT

<include refid="Base_Column_List" />

FROM

(

SELECT

id AS "id",

wechat_user_id AS "wechat_user_id",

weishangqiang_id AS "weishangqiang_id",

type AS "type",

own_screen_id AS "own_screen_id",

dashang_id AS "dashang_id",

dashang_tar_id AS "dashang_tar_id",

img_url AS "img_url",

content AS "content",

create_time AS "create_time",

theme_id AS "theme_id",

video_url AS "video_url",

to_wechat_user_id AS "to_wechat_user_id",

admin as "admin",

order_id as "order_id"

FROM

weishangqiang_content

WHERE

weishangqiang_id = #{weishangqiangId,jdbcType=INTEGER}

and create_time > str_to_date(#{lastTime,jdbcType=VARCHAR},'%Y-%m-%d %T')

ORDER BY

create_time DESC

) a

ORDER BY

a.create_time ASC

  </select>

大家看看这是什么意思,直接ASC不行吗,公司的老代码  需要优化

所有回答列表(4)
丶附耳聆听的gravatar头像
丶附耳聆听  LV21 2017年12月10日

... 目测是查询 weishangqiang_content 表 然后 按照创建时间排序

冰蓝色的雨的gravatar头像
冰蓝色的雨 2017年12月11日

这是个select标签 id已经把功能写很明白了select By WeishangqiangId In Order CreateTime Asc

这么断开还看不懂吗?

wjh0205的gravatar头像
wjh0205  LV3 2017年12月12日

SELECT

id AS "id",

wechat_user_id AS "wechat_user_id",

weishangqiang_id AS "weishangqiang_id",

type AS "type",

own_screen_id AS "own_screen_id",

dashang_id AS "dashang_id",

dashang_tar_id AS "dashang_tar_id",

img_url AS "img_url",

content AS "content",

create_time AS "create_time",

theme_id AS "theme_id",

video_url AS "video_url",

to_wechat_user_id AS "to_wechat_user_id",

admin as "admin",

order_id as "order_id"

FROM

weishangqiang_content

WHERE

weishangqiang_id = #{weishangqiangId,jdbcType=INTEGER}

and create_time > str_to_date(#{lastTime,jdbcType=VARCHAR},'%Y-%m-%d %T')

ORDER BY

${sortName} ${sortOrder}

可以将 传入参数时 sortName为create_time  sortOrder可以为ASC(升序),DESC(降序)排序

tommy5的gravatar头像
tommy5  LV11 2017年12月13日

SELECT   xxxx   FROM   weishangqiang_content    WHERE    weishangqiang_id=?(数据库里面的类型是integer) AND    create_time>?(数据库里面的varchar类型的时间格式换成:年-月-日 时:分:秒) ORDER BY 升序/降序

其中?部分为外界传递的参数。

顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友