Skip to content

Instantly share code, notes, and snippets.

@wulinlw
Created December 19, 2018 09:47
Show Gist options
  • Save wulinlw/f648e18ed56499f2dfe1ab2e36b3f781 to your computer and use it in GitHub Desktop.
Save wulinlw/f648e18ed56499f2dfe1ab2e36b3f781 to your computer and use it in GitHub Desktop.
使用变量的分表查询
set @uid=12345;
SET @tb=CONCAT('table_', lpad(mod(@uid, 64),2,0));
SET @sql = CONCAT('SELECT *,FROM_UNIXTIME(usedtime) FROM ',@tb,' where uid=', @uid);
PREPARE st FROM @sql;
EXECUTE st;
DEALLOCATE PREPARE st;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment