On Friday, March 15, 2019 at 7:06:38 PM UTC-7, Scott CL Himmelrich wrote:
>
> I have a table that I need to select all fields and then group where three 
> of the fields are the same (sample below Col1, Col2, Col3).  Group the 
> unique combinations of the three fields.  If there is only one record in 
> the group, report on it, if there is two or more then evaluate in this 
> order:  if Col6 = “X” select record, continue to next unique grouping, 
>  elseif Col6= “B” select record, continue to next unique grouping, elseif 
> Col6= “C” select that record....go to the next group (there are three 
> possible options always and I want them in the “X”,”B”,”C” order.  Sample 
> below 
>
> —————group—————— 
> Col1             Col2.         Col3.        Col4.        Col5.       Col6. 
> ABC.             TEN.        FOUR.         X.           L.             C. 
>    <—-Unique Row (selected to report on) 
> ABC.             TEN.        FIVE.           X.           L.             
>  C.   <—-Unique Row (selected to report on) 
> NNN.             JJJ.          LLL.            B.           L.             
>   B.   <—-Group Row 1 (B is second choice) 
> NNN.             JJJ.           LLL.           B.           L.             
>  X.    <—-Group Row 2 (X is first report it) 
>
> (Continue to next record or group)


I must admit that I don't really follow what you are asking for.  It would 
probably be easier if you listed your table of inputs and then the 
resulting output you expect.  It sounds like you may want to use DISTINCT 
ON if you are using PostgreSQL, or possibly a self join or subquery using 
GROUP BY if using another database.

In any case, it appears you don't know what SQL you want.  You should 
probably determine the SQL you want, and if you have questions about how to 
convert that SQL to Sequel code, post here with your SQL code and then I 
(or potentially someone else) could respond with a way to represent your 
SQL using Sequel.

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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to