I needed to pull out people who took a certain amount of classes in the last 3 years.
But there was not enough.
So I wanted to pull people who took a certain amount of classes in the last 5 years, as long as they also took any class within the last 3 years.
But there was not enough.
So I wanted to fill out the list with people who took at least a single class within the last year, deduping against the 1st list, and maintaining a separate list so when I extracted the data I could nth out the secondary list to achieve my final quantity.
Time to interactively develop this, including running a dozen times or so as I tuned my queries, about 10 minutes.
This would SUCK in any other language I've ever dealt with, and take hours to develop.
\n\ndrop table fin_primary;\n\ncreate table fin_primary as\n\tselect client_id id from res_aggr\n\twhere s_course in\n\t\t\t\t(\n\t\t\t\t'A021','A039','A057','A059','A061','A063','A071','A072',\n\t\t\t\t'A075','A090','A091','A097','A103','A105','A106','A113',\n\t\t\t\t'A119','A122','A135','A141','A142','A149','A150','A155',\n\t\t\t\t'A158','A159','A167','A168','A172','A176','A177','A178',\n\t\t\t\t'A179','A180','A183','A184','A185','A193','A194','A195',\n\t\t\t\t'A199','A200','A201','A202','O013','O023','O028','O033',\n\t\t\t\t'O057','O114','O125','O134','O135','O138','O140','A204',\n\t\t\t\t'A207','A209','A213','A217','A218','A232','A235','O149',\n\t\t\t\t'O150','O151','O153','O154','O155','O156'\n\t\t\t\t)\n\t\t\tand\n\t\t\t\tcourse_date > sysdate - (5 * 365)\n\t\t\tand\n\t\t\t\tattend = 'A'\n\t\t\tgroup by client_id\n\t\t\thaving count(*) > 2\n\tintersect\n\tselect unique(client_id) id from res_aggr\n\twhere course_date > sysdate - (3 * 365)\n\t\t\tand\n\t\t\t\tattend = 'A'\n;\n\nselect count(*) from fin_primary;\n\ndrop table fin_secondary;\n\ncreate table fin_secondary as\n\tselect unique (client_id) id from res_aggr\n\twhere s_course in\n\t\t\t\t(\n\t\t\t\t'A021','A039','A057','A059','A061','A063','A071','A072',\n\t\t\t\t'A075','A090','A091','A097','A103','A105','A106','A113',\n\t\t\t\t'A119','A122','A135','A141','A142','A149','A150','A155',\n\t\t\t\t'A158','A159','A167','A168','A172','A176','A177','A178',\n\t\t\t\t'A179','A180','A183','A184','A185','A193','A194','A195',\n\t\t\t\t'A199','A200','A201','A202','O013','O023','O028','O033',\n\t\t\t\t'O057','O114','O125','O134','O135','O138','O140','A204',\n\t\t\t\t'A207','A209','A213','A217','A218','A232','A235','O149',\n\t\t\t\t'O150','O151','O153','O154','O155','O156'\n\t\t\t\t)\n\t\t\tand\n\t\t\t\tcourse_date > sysdate - (1 * 365)\n\t\t\tand\n\t\t\t\tattend = 'A'\nminus\n\tselect id from fin_primary;\n\nselect count(*) from fin_secondary;\n