java用xml写的sql,select后面的查询字段中,最后三个查询不出来,如果把最后三个放在前面,又可以查询出来了,但是还是最后三个字段查询不出来。
SELECT
period.period_code AS PeriodCode,
period.period_go_time AS periodGoTime,
(
CASE
period.period_status
WHEN 1 THEN
'销售'
WHEN 2 THEN
'暂停'
WHEN 3 THEN
'售罄'
WHEN 4 THEN
'截团'
WHEN 5 THEN
'出团'
WHEN 6 THEN
'回团'
WHEN 7 THEN
'取消'
WHEN 8 THEN
'恢复' ELSE '未知状态'
END
) periodStatusName,
(
CASE
line.line_type
WHEN 1 THEN
'散拼'
WHEN 2 THEN
'考察'
WHEN 3 THEN
'旅居'
WHEN 4 THEN
'度假'
WHEN 5 THEN
'私人定制'
WHEN 6 THEN
'周边游'
WHEN 7 THEN
'一日游'
WHEN 8 THEN
'邮轮'
WHEN 9 THEN
'大型活动' ELSE '未知类型'
END
) lineTypeName,
(
SELECT
GROUP_CONCAT( plac.personnel_name SEPARATOR ',' )
FROM
li_personnel_placement AS plac
WHERE
plac.personnel_type = 3
AND period.id = plac.period_id
<if test="request.guideName !=null and request.guideName != ''">
AND plac.personnel_name like concat('%',#{request.guideName},'%')
</if>
) guideName,
(
SELECT
GROUP_CONCAT( plac.personnel_name SEPARATOR ',' )
FROM
li_personnel_placement AS plac
WHERE
plac.personnel_type = 2
AND period.id = plac.period_id
<!--领队-->
<if test="request.leaderName !=null and request.leaderName != ''">
AND plac.personnel_name like concat('%',#{request.leaderName},'%')
</if>
) leader_name,
(
SELECT
GROUP_CONCAT( placs.personnel_name SEPARATOR ',' )
FROM
li_personnel_placement AS placs
WHERE
placs.personnel_type = 1
AND period.id = placs.period_id
<!--保健医-->
<if test="request.doctorName !=null and request.doctorName != ''">
AND placs.personnel_name like concat('%',#{request.doctorName},'%')
</if>
) doctorName,
period.period_stock periodStock,
period.period_sell_stock periodSellStock,
period.period_surplus_stock periodSurplusStock,
period.period_code periodCode,
period.period_go_time periodGoTime,
period.period_back_time periodBackTime,
period.product_name productName,
period.tour_product_research_name tourProductResearchName,
period.period_minimum_clustering periodMinimumClustering,
line.line_name lineName,
product.supplier_company_name supplierName
FROM
li_regimental_period AS period
LEFT JOIN li_line_info line ON period.period_info_id = line.id
LEFT JOIN li_tour_product_info product ON period.period_product_id = product.id
WHERE
1 = 1
<!--团号-->
<if test="request.periodCode !=null and request.periodCode != ''">
AND period.period_code like concat('%',#{request.periodCode},'%')
</if>
<!--产品名称-->
<if test="request.tourProductName !=null and request.tourProductName != ''">
AND period.product_name like concat('%',#{request.tourProductName},'%')
</if>
<!--是否成团 :是-->
<if test="request.isRegimental !=null and request.isRegimental == 1">
AND period.period_sell_stock >= period.period_minimum_clustering
</if>
<!--是否成团:否-->
<if test="request.isRegimental !=null and request.isRegimental == 0">
AND period.period_sell_stock <= period.period_minimum_clustering
</if>
<!--线路类型-->
<if test="request.lineType !=null">
AND period.line_type == #{request.LineType}
</if>
<!--出团日期A-->
<if test="request.periodGoTimeA != null and request.periodGoTimeA !='' ">
and period.period_go_time >= #{request.periodGoTimeA}
</if>
<!--出团日期B-->
<if test="request.periodGoTimeB != null and request.periodGoTimeB !='' ">
and period.period_go_time <= #{request.periodGoTimeB}
</if>
<!--回团日期A-->
<if test="request.periodBackTimeA != null and request.periodBackTimeA !='' ">
and period.period_back_time >= #{request.periodBackTimeA}
</if>
<!--回团日期B-->
<if test="request.periodBackTimeB != null and request.periodBackTimeB !='' ">
and period.period_back_time <= #{request.periodBackTimeB}
</if>
</select>
比如现在在最后的是:periodMinimumClustering、lineName、supplierName,那么这三个就查不出来,不是没数据就是如果把他们三个放到前面就能查出来,这个sql在数据库跑过,完全可以查询出来,在java跑的时候生成的sql,在数据库跑了一遍也可以查询出来
以下是Java跑完代码生成的sql:
SELECT period.period_code AS PeriodCode, period.period_go_time AS periodGoTime, ( CASE period.period_status WHEN 1 THEN '销售' WHEN 2 THEN '暂停' WHEN 3 THEN '售罄' WHEN 4 THEN '截团' WHEN 5 THEN '出团' WHEN 6 THEN '回团' WHEN 7 THEN '取消' WHEN 8 THEN '恢复' ELSE '未知状态' END ) periodStatusName, ( CASE line.line_type WHEN 1 THEN '散拼' WHEN 2 THEN '考察' WHEN 3 THEN '旅居' WHEN 4 THEN '度假' WHEN 5 THEN '私人定制' WHEN 6 THEN '周边游' WHEN 7 THEN '一日游' WHEN 8 THEN '邮轮' WHEN 9 THEN '大型活动' ELSE '未知类型' END ) lineTypeName, ( SELECT GROUP_CONCAT( plac.personnel_name SEPARATOR ',' ) FROM li_personnel_placement AS plac WHERE plac.personnel_type = 3 AND period.id = plac.period_id ) guideName, ( SELECT GROUP_CONCAT( plac.personnel_name SEPARATOR ',' ) FROM li_personnel_placement AS plac WHERE plac.personnel_type = 2 AND period.id = plac.period_id ) leader_name, ( SELECT GROUP_CONCAT( placs.personnel_name SEPARATOR ',' ) FROM li_personnel_placement AS placs WHERE placs.personnel_type = 1 AND period.id = placs.period_id ) doctorName, period.period_stock periodStock, period.period_sell_stock periodSellStock, period.period_surplus_stock periodSurplusStock, period.period_code periodCode, period.period_go_time periodGoTime, period.period_back_time periodBackTime, period.product_name productName, period.tour_product_research_name tourProductResearchName, period.period_minimum_clustering periodMinimumClustering, line.line_name lineName, product.supplier_company_name supplierName FROM li_regimental_period AS period LEFT JOIN li_line_info line ON period.period_info_id = line.id LEFT JOIN li_tour_product_info product ON period.period_product_id = product.id WHERE 1 = 1 AND period.period_code like concat('%','Group-231100303','%') LIMIT 10