With a regular static query, you cannot define the column name as a variable / subquery, but you could achieve it using dynamic SQL ( prepared statements ):
SET @sql = CONCAT('select count(*) as `',(select date_sub(curdate(),interval 4 day)),'` from userinfo where createTime > (select date_sub(curdate(),interval 4 day));'); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SqlFiddleDemo
Output:
╔════════════╗ ║ 2016-01-14 ║ ╠════════════╣ ║ 2 ║ ╚════════════╝
source share