此查询方法有效:
SELECT xxx
FROM xxx-table
WHERE YEAR( CURRENT_DATE( ) ) - YEAR( '1988-10-27' )
- ( DATE_FORMAT( CURRENT_DATE( ) , '%m-%y' ) < '12-31' )
Between 20 and 25
但我需要的是这样的......
SELECT YEAR( CURRENT_DATE( ) )
- YEAR( '(Select xxx
From xxx-table
where year_id=9 limit 1)-10-27' )
- ( DATE_FORMAT( CURRENT_DATE( ) , '%m-%y' )
< '12-31' )
Between 20 and 25
我需要从数据库中提取值并使用子查询处理它,但它不起作用。我猜在功能上不允许子查询。有没有解决这个问题?
提前致谢!
答案 0 :(得分:2)
试试这个:
SELECT YEAR( CURRENT_DATE( ) )
- (Select xxx
From xxx-table
where year_id=9 limit 1)
- ( DATE_FORMAT( CURRENT_DATE( ) , '%m-%y' )
< '12-31' )
Between 20 and 25