1,如何在sql中查询时添加自增的序号
废话少说,直接上:
set @rownum=0;
SELECT
@rownum:=@rownum+1 as serialNumber,
#下面是你要查询的代码块
先定义,在增加。
set @rownum=0;
SELECT
@rownum:=@rownum+1 as serialNumber,
b.MEET_NAME,
b.START_TIME,
b.END_TIME,
e.PROJECT_NAME projectName,
( SELECT `NAME` FROM meeting_people WHERE FK_MEETING_INFO_ID = a.FK_MEETING_INFO_ID AND POSITION = '1' ) AS bigGroupLeader,
( SELECT `NAME` FROM meeting_people WHERE FK_MEETING_INFO_ID = a.FK_MEETING_INFO_ID AND POSITION = '2' ) AS smallGroupLeader,
( SELECT GROUP_CONCAT( `NAME` ) FROM meeting_people WHERE FK_MEETING_INFO_ID = a.FK_MEETING_INFO_ID AND POSITION = '3' ) AS teamPeople,
( SELECT COUNT( `NAME` ) FROM meeting_people WHERE FK_MEETING_INFO_ID = a.FK_MEETING_INFO_ID AND POSITION = '3' ) AS tempPeopleNum,
( SELECT COUNT( `NAME` ) FROM meeting_people WHERE FK_MEETING_INFO_ID = a.FK_MEETING_INFO_ID AND POSITION = '4' ) AS practiceStudentNum,
( SELECT REAL_NAME FROM sys_user WHERE SYS_USER_ID = b.PROJECT_MANAGER ) AS projectManagerName,
( SELECT REAL_NAME FROM sys_user WHERE SYS_USER_ID = b.PROVINCIAL_MANAGER ) AS provincialManager,
(
SELECT
DICT_LABEL
FROM
sys_dict_data
WHERE
DICT_VALUE = b.CONFERENCE_LEVEL
AND `STATUS` = '1'
AND FK_DICT_TYPE_ID = ( SELECT SYS_DICT_DATA_TYPE_ID FROM sys_dict_data_type WHERE `STATUS` = '1' AND DICT_TYPE = 'empLevel' )) AS conferenceLevel,
b.CONTACT_USER brokerUser,
b.`PHONE` custTel,
a.PRODUCT_SCORE productScore,
a.SERVICE_QUALITY serviceQuality,
a.SERVICE_ATTITUDE serviceAttitude,
a.SATISFY_RECORD satisfyRecord,
a.IDEA_RECORD ideaRecord,
a.IDEA_TYPE ideaType,
ri.CAUSE_ANALYSIS causeAnalysis,
ri.IMPROVE_WAY improveWay,
( SELECT REAL_NAME FROM sys_user WHERE SYS_USER_ID = ri.IMPROVER ) AS improver,
ri.IMPROVE_TIME improveTime,
ISNULL(ri.REPLY_RESULT) as replyResult,
a.IMPROVE_PROGRESS improveProgress,
( SELECT REAL_NAME FROM sys_user WHERE SYS_USER_ID = a.REAL_REVISITER ) AS realRevisiter,
a.REVISIT_TIME revisitTime
FROM
revisit_base_info a
LEFT JOIN revisit_improve_info ri ON ri.FK_REVISIT_BASE_INFO_ID = a.REVISIT_BASE_INFO_ID
LEFT JOIN meeting_info b ON a.FK_MEETING_INFO_ID = b.MEETING_INFO_ID
LEFT JOIN project_type e ON b.FK_PROJECT_TYPE_ID = e.PROJECT_TYPE_ID AND e.DEL_FLAG = '0'
LEFT JOIN risk_accident_info ra on ra.FK_MEETING_INFO_ID = a.FK_MEETING_INFO_ID and ra.DEL_FLAG = '0'
WHERE
a.DEL_FLAG = '0'
AND b.DEL_FLAG = '0'
<if test="startDate != null">
AND b.END_TIME >= #{startDate}
</if>
<if test="endDate != null">
AND b.END_TIME <= #{endDate}
</if>
<if test="meetName != null and meetName != ''">
AND b.MEET_NAME LIKE CONCAT('%',#{meetName},'%')
</if>
<if test="revisitStatus != null and revisitStatus != ''">
AND a.REVISIT_STATUS = #{revisitStatus}
</if>
<if test="meetType != null and meetType != ''">
AND b.FK_PROJECT_TYPE_ID = #{meetType}
</if>
<if test="conferenceLevel != null and conferenceLevel != ''">
AND b.CONFERENCE_LEVEL = #{conferenceLevel}
</if>
<if test="ifRisk != null">
AND ISNULL(ra.RISK_ACCIDENT_INFO_ID) = #{ifRisk}
</if>
<if test="improveProgress != null and improveProgress != ''">
AND a.IMPROVE_PROGRESS = #{improveProgress}
</if>
<if test="revisitDate != null and revisitDate != ''">
AND DATE_FORMAT(a.REVISIT_TIME,'%Y-%m-%d') = #{revisitDate}
</if>
<if test="deptName != null and deptName != ''">
AND b.`UNIT` = #{deptName}
</if>
<if test="ifHighLight != null and ifHighLight == 1">
AND a.REVISIT_TIME > DATE_ADD(b.END_TIME,INTERVAL 10 DAY)
</if>
<if test="ifHighLight != null and ifHighLight == 0">
AND a.REVISIT_TIME <= DATE_ADD(b.END_TIME,INTERVAL 10 DAY)
</if>
order by a.REVISIT_STATUS, b.CREATE_TIME, e.SORT_NO
这里 ISNULL(ri.REPLY_RESULT) as replyResult,
的使用就是为了判断某个字段是否存在,返回一个Boolean