sql中如何添加自增序号或ISNULL的使用

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 &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            AND b.END_TIME &lt;= #{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 &lt;= 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

焚目圣僧渡众生

你的 一角将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值