计算内部查询中的年龄,然后与值进行比较

时间:2013-02-23 23:59:18

标签: oracle11g

我有两张桌子。

  1. fbuser(facebook_ID,date_of_birth) - facebook_id是主键
  2. wall(wall_ID,facebook_ID,public_view) - facebook_id是外键
  3. 我想找到将墙设置为公共视图并且年龄超过24岁的用户?

    Select f.facebook_ID from fbuser f, wall w 
    WHERE
      (w.public_view='y')
     AND
      (f.facebook_ID=w.facebook_ID)
     AND
      (select FLOOR( MONTHS_BETWEEN( CURRENT_DATE, f.date_of_birth ) / 12 ) 
      as person_age from fbuser where person_age >=24; 
    

1 个答案:

答案 0 :(得分:1)

SELECT
  f.facebook_ID
FROM fbuser f, wall w 
WHERE
  (f.facebook_ID=w.facebook_ID)
 AND
  (w.public_view='y')
 AND
  (  (MONTHS_BETWEEN( CURRENT_DATE, f.date_of_birth )/12)  >=24);