doutizhou5312 2017-06-07 12:35
浏览 334
已采纳

MySQL如何在虚拟字段定义中实现条件

I'm using the PHP function below to calculate checksums for strings in PHP. The xor is required to produce the same value on 32 and 64 bit php platforms.

I would like to create a virtual field in MySQL select queries that will have the same value. SELECT ABS(CRC32(ui_data)) As checksum FROM user_data works but I don't know how to implement the if part in a SELECT statement to make it fully compatible to the PHP function.

10X

function checksum ($orig_id) {
    $crc= abs (crc32($orig_id));
    if( $crc & 0x80000000){
      $crc ^= 0xffffffff;
      $crc += 1;
     }
    return $crc;
}
  • 写回答

1条回答 默认 最新

  • duanke0178 2017-06-07 13:16
    关注
    SELECT IF(@crc & 0x80000000, @crc ^ 0xffffffff, @crc + 1)
    FROM (SELECT @crc := ABS(CRC32('your_value'))) v
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?