On Friday, January 10, 2020 at 12:35:55 PM UTC-8, Todd wrote:
>
> I'm a Sequel noobie and I either don't understand the DSL correctly and/or 
> simply missing something that's obvious. I want to do this...
>
> SELECT nutrient, a.amt + b.amt AS total FROM anatomy a JOIN anatomy b 
> USING (nutrient) WHERE a.food = '23575' AND b.food = '31008';
>

Sequel code:

DB.from{anatomy.as(:a)}.
  join(:anatomy, [:nutrient], :table_alias=>:b).
  select{[:nutrient, (a[:amt] + b[:amt]).as(:total)]}.
  where{{a[:food]=>'23575', b[:food]=>'31008'}}

SQL generated:

SELECT nutrient, (a.amt + b.amt) AS total FROM anatomy AS a INNER JOIN 
anatomy AS b USING (nutrient) WHERE ((a.food = '23575') AND (b.food = 
'31008'))

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/d426b241-dc61-47ba-be28-1234ec1d4624%40googlegroups.com.

Reply via email to