meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
pluginto:useful_sql_queries [2023/10/19 21:46] – joetulenko | pluginto:useful_sql_queries [2024/12/03 17:29] (current) – joetulenko | ||
---|---|---|---|
Line 258: | Line 258: | ||
If you want an EXACT match, omit the %'s inside the parentheses. Although this statement is still not case sensitive, just FYI.// | If you want an EXACT match, omit the %'s inside the parentheses. Although this statement is still not case sensitive, just FYI.// | ||
+ | |||
+ | ---- | ||
+ | |||
+ | \\ | ||
+ | |||
+ | 7. Filtering selection by choosing samples from sites that have AT LEAST 3 samples per site. For example, let's say I only trust moraine ages in the database that are based on at least 3 boulder ages on the moraine, any less and the age might be uncertain.\\ | ||
+ | **New Feature:** lots of new features in this one, but mainly the GROUP_BY and HAVING COUNT (*) built-in functions. | ||
+ | |||
+ | < | ||
+ | |||
+ | SELECT base_sample.name, | ||
+ | FROM base_sample | ||
+ | JOIN base_site ON base_site.id = base_sample.site_id | ||
+ | WHERE base_site.what LIKE " | ||
+ | AND base_sample.site_id IN | ||
+ | (SELECT base_sample.site_id FROM base_sample GROUP BY base_sample.site_id HAVING COUNT(*) > 2) | ||
+ | |||
+ | </ | ||
+ | |||
+ | //note: the statement before and within the parentheses (I think) works more or less like this:\\ | ||
+ | 1. "AND base_sample.site_id IN" = give me all samples where their site_id field meets the following criteria.\\ | ||
+ | 2." | ||
+ | 3. " | ||
+ | |||
+ | ---- | ||
+ | |||
+ | \\ | ||
+ | |||
+ | 8. Query used to filter the ICE-D Alpine application for samples in the Cascades and Sierra Nevada as part of Tulenko et al. (2024): Cosmogenic 21Ne exposure ages on late Pleistocene moraines in Lassen Volcanic National Park, California, USA. | ||
+ | |||
+ | < | ||
+ | |||
+ | SELECT base_sample.name, | ||
+ | FROM base_sample | ||
+ | JOIN base_site ON base_sample.site_id = base_site.id | ||
+ | JOIN base_calculatedage ON base_calculatedage.sample_id = base_sample.id | ||
+ | WHERE base_sample.what LIKE " | ||
+ | AND base_site.what LIKE " | ||
+ | AND base_sample.site_id IN | ||
+ | (SELECT base_sample.site_id FROM base_sample GROUP BY base_sample.site_id HAVING COUNT(*) > 3) | ||
+ | AND (base_sample.lat_DD > 35 AND base_sample.lat_DD < 48) | ||
+ | AND (base_sample.lon_DD > -123 AND base_sample.lon_DD < -117) | ||
+ | AND (base_calculatedage.t_LSDn > 10000 AND base_calculatedage.t_LSDn < 35000) | ||
+ | ORDER BY base_sample.lat_DD | ||
+ | |||
+ | </ | ||
---- | ---- | ||
\\ | \\ |