1

我有两张桌子。

  1. fbuser(facebook_ID, date_of_birth) - facebook_id 是主键
  2. wall(wall_ID, facebook_ID, public_view) - facebook_id 是外键

我想查找将墙设置为公开视图且年龄超过 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; 
4

1 回答 1

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); 
于 2013-02-24T00:21:55.960 回答