What's the best way to select max over multiple fields in SQL? -
The maximum selection I want to do is to select (f1, f2, f3). I know this is not working, but I think what I want should be very clear (see Update 1).
I was thinking of making the maximum selection (contact (F1, '-', F2 ...)), but it has various disadvantages. In particular, contacting will probably slow things down. What is the best way to get what I want?
Update 1: The answers I have so far received are not those which I am doing later. Works on a set of maximum records, but it uses only one value; I want to consider a number of values to consider, as can consider many values.
Update 2: Suppose I have the following table:
id class_name order_by1 order_by_2 1 a 0 0 2 a 0 1 3b1 0bb 9 9< P> I want a query that will group the record by class_name. Then, within each "square", select the record that will come first if you are ordered by
order_by1
ascending order_by2
ascending in the result set record 2 and 3 . Will be included. In my magical query language, it will look something like this: Select Max_ (order order by BBA ASC, Order-B2 ASC) from class group name class_name
Choose from the maximum (val) (maximum select) FD2 2) As the value of your cable system, ) Select
to your maximum as MAX MAX (fld2) THEN MAX (fld3) END Edit: Another option is:
Select when MAX (fld1)> gt; ; = MAX (fld2) and MAX (fld1) & gt; = MAX (fld3) THEN MAX (fld1) WHEN MAX (fld2)> = MAX (fld1) and MAX (fld2) & Gt; = MAX (fld3) THEN MAX (fld2) WHEN MAX (fld3)> = MAX (fld1) and MAX (fld3) & gt;
Comments
Post a Comment