sql >> データベース >  >> RDS >> Mysql

IF / THEN/ELSEを使用したMySQLストアドプロシージャ

    この構成を試してください

    WHILE (@RowCnt <= @MaxRows)
    BEGIN
        SELECT @currentReadSeq:=ReadSeq, @currentReadStrength:=ReadStrength, @currentReadDateTime:=ReadDateTime, @currentReaderID:=ReaderID FROM tblTempRead WHERE rownum = @RowCnt;
    
        IF (((@lastReadSeq + 10) > @currentReadSeq) AND (@lastReaderId = @currentReaderId))
            BEGIN
            SET @lastReadSeq = @currentReadSeq, @lastReadStrength = @currentReadStrength, @lastReadDateTime = @currentReadDateTime, @lastReaderID = @currentReaderID;
            END
        ELSE
            BEGIN
            INSERT INTO tblreaddataresults (SiteID, ReadDateTimeStart, ReadDateTimeEnd,ReadSeqStart, ReadSeqEnd, ReaderID, DirectSeconds) VALUES ('1002',@saveReadDateTime, @lastReadDateTime, @saveReadSeq, @lastReadSeq, @lastReaderID,timestampdiff(SECOND,@saveReadDateTime,@lastReadDateTime));
            SET @saveReadSeq = @currentReadSeq, @saveReadStrength = @currentReadStrength, @saveReadDateTime = @currentReadDateTime, @saveReaderID = @currentReaderID;
            SET @lastReadSeq = @saveReadSeq, @lastReadStrength = @saveReadStrength,@lastReadDateTime = @saveReadDateTime, @lastReaderID = @saveReaderID;
            END
        SET @RowCnt = @RowCnt+1;
    END
    



    1. ルートパスワードをリセットできません:Windows、MySQL8.0

    2. 制約違反の例外ORA-00001

    3. group Byを使用してSQLにLinqし、カウントで並べ替える

    4. CONCAT()を使用してMySQLの文字列を連結する方法