// SQL
SELECT m.* FROM meme m JOIN (SELECT aid FROM meme GROUP BY aid HAVING SUM(CASE WHEN (rid='pres_order' AND qnt>=20) THEN 1 ELSE 0 END) > 0 AND SUM(CASE WHEN (rid='pres_order' AND qnt<=30) THEN 1 ELSE 0 END) > 0) AS aids ON m.aid = aids.aid WHERE m.rid IN ('spouse') OR (rid='pres_order' AND qnt>=20) OR (rid='pres_order' AND qnt<=30);
A.R:B=Q
james_garfield.spouse:lucretia_rudolph_garfield=1
chester_arthur.spouse:ellen_lewis_herndon_arthur=1
grover_cleveland.spouse:frances_folsom_cleveland=1
benjamin_harrison.spouse:lavinia_scott_harrison=1
william_mckinley.spouse:ida_saxton_mckinley=1
theodore_roosevelt.spouse:alice_hathaway_lee_roosevelt=1
theodore_roosevelt.spouse:edith_kermit_carow=1
william_taft.spouse:helen_herron_taft=1
woodrow_wilson.spouse:ellen_louise_axson=1
woodrow_wilson.spouse:edith_wilson=1
warren_harding.spouse:florence_kling_harding=1
calvin_coolidge.spouse:grace_anna_goodhue_coolidge=1
james_garfield.pres_order:first=20
chester_arthur.pres_order:first=21
grover_cleveland.pres_order:first=22
benjamin_harrison.pres_order:first=23
grover_cleveland.pres_order:second=24
william_mckinley.pres_order:first=25
theodore_roosevelt.pres_order:first=26
william_taft.pres_order:first=27
woodrow_wilson.pres_order:first=28
warren_harding.pres_order:first=29
calvin_coolidge.pres_order:first=30
Example Queries (Help)
qry.all Show all data in this DB.
george_washington All about George Washington.
.child Who were children of the presidents?
:lawyer Which presidents were lawyers?
.college:harvard Which presidents attended Harvard for college?
.pres_order=10 Who was the tenth president?
.college:columbia .occupation:lawyer Which presidents attended Columbia and were lawyers?
.pres_order>=20 .pres_order<=30 Who were the twentieth through thirtieth presidents?
.pres_order .child=f Which presidents did NOT have children?
.pres_order>=20 .pres_order<=30 .spouse=g Who were the spouses of the twentieth through thirtieth presidents?
.college:harvard .college:columbia qry.all Use qry.all to return all memes related to the matching As.