SQL - find the minimum value for each separate record...

Hi all

I have a table like this in SQL Server

Date of sale of product
A date
A date
A date
B date of
B date of
C date
C date
C date

I would like to write a query to find the minimum date (i.e. the date
the first sale) for each product

Thus, the expected results would be

Date of sale of product
A date min
B date of min
C date of min

How can I do this using SQL Server?

any help is greatly appreciated!

Thank you!

Product SELECTION, MIN (sale_date)
From your_table
GROUP BY product

Etienne

Tags: ColdFusion

Similar Questions

  • Determine the maximum value and the minimum value for each value in the 2D array

    Hello, I need help please. Sorry my English is not very good. I have table 2D in which each value describes a waveform, I needed a time interval to determine the minimum and maximum value of each element of the array.


  • PL/SQL loop to find the minimum value

    I want to find the minimum value from a table using the pl/sql loop

    I have data format below.

    1 ABC 2

    1 ABC 20

    1 ABC 500

    1 ABC 2000

    XYZ 2 250

    JKL 3 300

    MNP 3 350

    3 KLM 400

    I wrote the code below. His does not work. Please suggest.

    Set serveroutput on
    declare
    x number: = 3;
    y VARCHAR2 (3): = 'ABC ';
    fmin number: = 0;
    number of Fmax: = 0;
    Start
    for rec in (select sal from test
    where id = name and x = y) loop


    If rec.sal > fmin then
    fmin: = rec.sal;
    on the other
    FMAX: = rec.sal;
    fmin: = fmax.
    end if;
    end loop;
    dbms_output.put_line (Fmax);
    end;
    /

    I want to output 2 on top of code.

    Thanks in advance

    Why PL/SQL? SELECT MIN (SAL) OF TEST will be more rapid and much less coding. In any case:

    declare

    number of v_min_sal;

    Start

    for v_rec in a loop (select sal from emp)

    If nvl (v_min_sal, v_rec.sal + 1) > v_rec.sal

    then

    v_min_sal: = v_rec.sal;

    end if;

    end loop;

    dbms_output.put_line (' lowest salaray is "' |") v_min_sal | '"');

    end;

    /

    The lowest Salaray is "800".

    PL/SQL procedure successfully completed.

    SQL >

    SY.

  • How to find the child level for each table in a relational model?

    Earthlings,

    I need your help, and I know that, "Yes, we can change." Change this thread to a question answered.

    So: How to find the child level for each table in a relational model?

    I have a database of relacional (9.2), all right?
    .
         O /* This is a child who makes N references to each of the follow N parent tables (here: three), and so on. */
        /↑\ Fks
       O"O O" <-- level 2 for first table (circle)
      /↑\ Fks
    "o"o"o" <-- level 1 for middle table (circle)
       ↑ Fk
      "º"
    Tips:
    -Each circle represents a table;
    -Red no tables have foreign key
    -the picture on the front line of tree, for example, a level 3, but when 3 becomes N? How is N? That is the question.

    I started to think about the following:

    First of all, I need to know how to take the kids:
    select distinct child.table_name child
      from all_cons_columns father
      join all_cons_columns child
     using (owner, position)
      join (select child.owner,
                   child.constraint_name fk,
                   child.table_name child,
                   child.r_constraint_name pk,
                   father.table_name father
              from all_constraints father, all_constraints child
             where child.r_owner = father.owner
               and child.r_constraint_name = father.constraint_name
               and father.constraint_type in ('P', 'U')
               and child.constraint_type = 'R'
               and child.owner = 'OWNER') aux
     using (owner)
     where child.constraint_name = aux.fk
       and child.table_name = aux.child
       and father.constraint_name = aux.pk
       and father.table_name = aux.father;
    Thought...
    We will share!

    Thanks in advance,
    Philips

    Published by: BluShadow on April 1st, 2011 15:08
    formatting of code and hierarchy for readbility

    Have you looked to see if there is a cycle in the graph of dependence? Is there a table that has a foreign key to B and B has a back of A foreign key?

    SQL> create table my_emp (
      2    emp_id number primary key,
      3    emp_name varchar2(10),
      4    manager_id number
      5  );
    
    Table created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  create table my_mgr (
      2    manager_id number primary key,
      3    employee_id number references my_emp( emp_id ),
      4    purchasing_authority number
      5* )
    SQL> /
    
    Table created.
    
    SQL> alter table my_emp
      2    add constraint fk_emp_mgr foreign key( manager_id )
      3         references my_mgr( manager_id );
    
    Table altered.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1   select level lvl,
      2          child_table_name,
      3          sys_connect_by_path( child_table_name, '/' ) path
      4     from (select parent.table_name      parent_table_name,
      5                  parent.constraint_name parent_constraint_name,
      6                  child.table_name        child_table_name,
      7                  child.constraint_name   child_constraint_name
      8             from user_constraints parent,
      9                  user_constraints child
     10            where child.constraint_type = 'R'
     11              and parent.constraint_type = 'P'
     12              and child.r_constraint_name = parent.constraint_name
     13           union all
     14           select null,
     15                  null,
     16                  table_name,
     17                  constraint_name
     18             from user_constraints
     19            where constraint_type = 'P')
     20    start with child_table_name = 'MY_EMP'
     21*  connect by prior child_table_name = parent_table_name
    SQL> /
    ERROR:
    ORA-01436: CONNECT BY loop in user data
    

    If you have a cycle, you have some problems.

    (1) it is a NOCYCLE keyword does not cause the error, but that probably requires an Oracle version which is not so far off support. I don't think it was available at the time 9.2 but I don't have anything old enough to test on

    SQL> ed
    Wrote file afiedt.buf
    
      1   select level lvl,
      2          child_table_name,
      3          sys_connect_by_path( child_table_name, '/' ) path
      4     from (select parent.table_name      parent_table_name,
      5                  parent.constraint_name parent_constraint_name,
      6                  child.table_name        child_table_name,
      7                  child.constraint_name   child_constraint_name
      8             from user_constraints parent,
      9                  user_constraints child
     10            where child.constraint_type = 'R'
     11              and parent.constraint_type = 'P'
     12              and child.r_constraint_name = parent.constraint_name
     13           union all
     14           select null,
     15                  null,
     16                  table_name,
     17                  constraint_name
     18             from user_constraints
     19            where constraint_type = 'P')
     20    start with child_table_name = 'MY_EMP'
     21*  connect by nocycle prior child_table_name = parent_table_name
    SQL> /
    
           LVL CHILD_TABLE_NAME               PATH
    ---------- ------------------------------ --------------------
             1 MY_EMP                         /MY_EMP
             2 MY_MGR                         /MY_EMP/MY_MGR
             1 MY_EMP                         /MY_EMP
             2 MY_MGR                         /MY_EMP/MY_MGR
    

    (2) If you try to write on a table and all of its constraints in a file and do it in a valid order, the entire solution is probably wrong. It is impossible, for example, to generate the DDL for MY_EMP and MY_DEPT such as all instructions for a table come first, and all the instructions for the other are generated second. So even if NOCYCLE to avoid the error, you would end up with an invalid DDL script. If that's the problem, I would rethink the approach.

    -Generate the DDL for all tables without constraint
    -Can generate the DDL for all primary key constraints
    -Can generate the DDL for all unique key constraints
    -Can generate the DDL for all foreign key constraints

    This is not solidarity all the DOF for a given in the file object. But the SQL will be radically simpler writing - there will be no need to even look at the dependency graph.

    Justin

  • Find the minimum value of the table in time...

    Firstly that it is not "find the min value in the table.

    It is:

    I have a table that changes its values at each iteration, and I want to compare the new values with previous values and make a new array with the minimum values...

    In C++, it would be like this:

    int main() {}

    int array [8];

    int min [8];

    int i;

    for (i = 0; i<>

    min [i] = 1000000; Initialize minimum table with a high value

    }

    {while (1)}

    Array = update_array ();

    for (i = 0; i<>

    If (array [i]<>

    min [i] = array [i];

    }

    }

    do things...

    }

    return 0;

    }

    IM new to labview and it always confuses me a lot...

    Thanks in advance.

    Using the function Max & Min regular (not table Max & min as you know) with tables and a good will of employment registry change.  Max Min &, as most of the digital functions, is polymorphic and works witt tables as well as scalars.

    Lynn

  • Where can I find the numerical value for GenICam standard pixel formats?

    I am putting in place a structure of case for the reconstruction of image formats using the pixel as IMAQdx output format. Confirmed the consistent property of 'Pixel Format' numeric U32 in id IMAQdx from camera to camera, but it's just a number, and I don't see that the number of image formats used by the cameras I (I need code for other formats I've yet to see). The GenICam standard 1.1 supports 52 image formats, and no doubt IMAQdx has a corresponding U32 value for each format. Where can I find this list? The .pdf for the GenICam standard lists the formats available in name only and does not have a corresponding numerical value.

    Hey Nasgul

    The attribute 'PixelFormat' is actually a list of name/value pairs. For GenICam cameras (such as GigE Vision) these names and these values are determined by the camera, no IMAQdx XML file. The names themselves are normalized by the part of the "Standard feature Naming Convention" of GenICam (but aren't their values).

    I think you speak for the Format of Pixel property node. I think you are right that it is a digital. It's probably because the available modes can not be known before you actually run the code and the LabVIEW enumeration values must be known when editing, no compilation. The node itself as a digital is probably as a relic of the firewire interface. It would be probably more useful as a string, I imagine.

    You probably want to use the generic way of manipulating the attributes instead. You initially set the property 'Attribute Active' in 'PixelFormat' and then you can then query a list of name/value pairs available or simply set the value. IMAQdx allows you to set the value directly as a string (using the standard names) rather than having to translate it into a numeric value.

    Eric

  • Select the last value for each day of the table

    Hello!

    I have a table that contains several measures for each day. I need two queries on this table, and I'm not sure how to write them.

    The table stores the rows (sample data)
    *DateCol1                 Value       Database*
    27.09.2009 12:00:00       100           DB1
    27.09.2009 20:00:00       150           DB1
    27.09.2009 12:00:00       1000          DB2
    27.09.2009 20:00:00       1100          DB2
    28.09.2009 12:00:00       200           DB1
    28.09.2009 20:00:00       220           DB1
    28.09.2009 12:00:00       1500          DB2
    28.09.2009 20:00:00       2000          DB2
    Explanation of the data in the sample table:
    We measure the size of the data files belonging to each database to one or more times a day. The value column indicates the size of the files of database for each database at some point (date in DateCol1 European model).


    What I need:
    Query 1:
    The query must return to the last action for each day and the database. Like this:
    *DateCol1       Value      Database*
    27.09.2009        150          DB1
    27.09.2009       1100          DB2
    28.09.2009        220          DB1
    28.09.2009       2000          DB2
    Query 2:
    The query should return the average measurement for each day and the database. Like this:
    *DateCol1       Value      Database*
    27.09.2009       125          DB1
    27.09.2009      1050          DB2
    28.09.2009       210          DB1
    28.09.2009      1750          DB2
    Could someone please help me to write these two queries?

    Please let me know if you need further information.

    Published by: user7066552 on September 29, 2009 10:17

    Published by: user7066552 on September 29, 2009 10:17

    Why two queries when it suffice ;)

    SQL> select dt
      2       , db
      3       , val
      4       , avg_val
      5    from (
      6  select dt
      7       , val
      8       , db
      9       , row_number () over (partition by db, trunc (dt)
     10                                 order by dt desc
     11                            ) rn
     12       , avg (val) over (partition by db, trunc (dt)) avg_val
     13    from test)
     14   where rn = 1
     15  order by dt
     16  /
    
    DT        DB           VAL    AVG_VAL
    --------- ----- ---------- ----------
    27-SEP-09 DB2         1100       1050
    27-SEP-09 DB1          150        125
    28-SEP-09 DB2         2000       1750
    28-SEP-09 DB1          220        210
    
  • Take the minimum value for table data

    I'm storing test data in a table, with the hope that I can output the minimum value of the data. So far, I have used the table of max/min but can't make it work how I want. The test runs continuously in a loop of the holder. I get the minimum values in the table, but I would like to change the number of samples that the table contains, before it generates a minimum. The other option is that I run the test for a period of time (e.g. 3 seconds) and the table stores the data for this time then output 1 minimum value for the entire period.

    My current configuration VI is attached.

    Very appreciated

    Chris

    The size of the array in your VI is determined by the number of samples that you collect in your DAQ assistant, who is now 100 samples.  Never more, never less.

    How many samples do you want before you determine the minimum?

    Maybe what you really want to do is to build the table in the while loop and store it in a shift register, and when the loop has repeated enough times, then you take the minimum of built table.

  • What is the minimum value for the data type double?

    ... a more academic question: what is the minimum value of the data type double? I thought 'double', it is the 8-byte IEEE standard and what I remember, it's + - 1.7E + - 308.  The more different number of 0 should be 1.797E - 308.

    This is why I was a little surprised when I looked at the data output of my calculation of CVI, where I found the numbers with exponents of E-319 or E-324 as the smallest value...

    But I'm sure there's an explanation :-)

    Thank you for sharing with me,

    Wolfgang

    The largest number is indeed the order of + 1.7E + 308; There are a smaller number of - 1.7E + 308. Note that this is in fact the most negative number, which is the smallest by some reckoning. For the small beach of the Exhibitor, things get a little more complicated. 1E-308 can be represented with complete accuracy and resolution, but if you're willing to lose a few bits of precision, you can go down even further. For example:

    Double x, y, z:

    x = 1E-300;

    y = 1E7;

    z = x / y;               Give 1.000000000000000E - 307

    y = 1E8;

    z = x / y;               Give 9.999999999999999E - 309

    y = 1E18;

    z = x / y;               Give 9.999987484955998E - 319

    y = 1E23;

    z = x / y;               Give 9.881312916824931E - 324

    So, as you can see, values less than 1E-308 are possible, but they become increasingly more inaccurate and should not be relied upon.

    JR

  • How to find the rank lowest for each student using a Select query?

    Hey I'm having a little trouble here

    I have this table


    Student - Grade

    John - 8
    Richard - 9
    Louis - 9
    Francis - 5
    John - 13
    Richard - 10
    Peter - 12

    Shades may vary from 0 to 20.

    Name - varchar (50)
    Grade - wide

    I'm trying to generate a SQL search to search for each rank lowest for each student.

    So far, I did:

    Select s.name, s.grade
    s student
    where s.grade = (select min (grade) of student)

    The result of this search returns me only the rank lowest of all ranks posted above, which is Francis - 5.

    I want to find the lowest rank, but not only for Francis, but for all students in the table.

    How do I do that?

    Thank you in advance.

    Ok

    Now we head into analytical SQL:

    with student as (select 'John' name, 8 grade, 'fail' result from dual union all
                     select 'John' name, 13 grade, 'pass' result from dual union all
                     select 'Francis',     5 grade,  'fail' from dual union all
                     select 'Peter', 12, 'pass' from dual)
    -- End of your test data
    SELECT   name,
             MAX (result) KEEP (DENSE_RANK FIRST ORDER BY grade) result,
             MIN (grade) min_grade
    FROM     student
    GROUP BY name
    

    Please note that I passed ;)

    Concerning
    Peter

    To learn more:
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions056.htm#SQLRF00641

  • How do you find the current value of each sample when collecting a finite number of samples

    My program works with an external clock with no constant pulse intervals and acquires a value of voltage on the front of these impulses.  Is there anyway to get the value of the voltage at each pulse without having to wait until all samples are taken.  I would Normal 0 false false false MicrosoftInternetExplorer4 / * Style Definitions * / table. MsoNormalTable {mso-style-name: "Table Normal" "; mso-knew-rowband-size: 0; mso-knew-colband-size: 0; mso-style - noshow:yes; mso-style-parent:" ";" mso-padding-alt: 0 cm 0 cm 5.4pt 5.4pt; mso-para-margin: 0 cm; mso-para-margin-bottom: .0001pt; mso-pagination: widow-orphan; do-size: 10.0pt; do-family: "Times New Roman"; mso-ansi-language: #0400; mso-fareast-language: #0400; mso-bidi-language: #0400 ;} programmatically raises an event when the voltage reaches a certain level during the scan if so why I need to constantly monitor the voltage. "}

    Any help would be great

    Hi JED1986

    I have two solutions for you, for your problem.

    The first idea I would recommend creates the code below:

    Remembeer to define the sources correctly, including the clock to read source as your external clock. The above code will be permanently read 1 single sample with a rising edge, write to the disk, clear and will continue to read the following sample.

    Another way to proceed is to use an express VI and set the mode of acquisition as ' on demand ' with 1 sample currently playing. This is illustrated below and highlighted in red:

    I hope this helps. Please let me know how you go.

  • SQL, find the MAX value and placing it as a QVariant

    I have a database that is loaded and defines the customerID as 0 which is ideal when the database is not be saved and restored, etc.  The question I have is that I added the possibility to users to restore a backup in the app, and now I have to do a query to select MAX (customerID) so that there is no duplicate CustomerID when you add or save items.  Here is the following code, I knew that I must settle, specifically the 0 highlighted in red.  I need zero to be the new customerID max value:

    int SettingsStorage::load(int& lastID, GroupDataModel *model)
    {
        // number of locations loaded.
        QSettings settings(m_author, m_appName);
        int loadedCount = 0;
    
        QVariant items;
        // Get the last customer id first.
        // ID's will be generated by incrementing this number
        // Note values coming from settings should be cast to the
        // required type.
         lastID = settings.value(m_lastCustomerIDKey, 0).toInt();
        items = m_sda->execute("SELECT * from items ORDER BY datefield");
        qDebug()<< "the ID" << items;
        // Load all the locations from the database.
        foreach( const QVariant& temp, items.value() ) {
            Location *p;
            if (loadLocation(temp.value(), p)) {
                model->insert(p);
                loadedCount++;
            }
        }
        return loadedCount;
    }
    

    Ive tried the following, but it doesn't seem to do anything:

    int SettingsStorage::load(int& lastID, GroupDataModel *model)
    {
        // number of locations loaded.
        QSettings settings(m_author, m_appName);
        int loadedCount = 0;
    
        QVariant items;
        // Get the last customer id first.
        // ID's will be generated by incrementing this number
        // Note values coming from settings should be cast to the
        // required type.
         QVariant endID = m_sda->execute("Select MAX(customerID) from items")
         lastID = settings.value(m_lastCustomerIDKey, endID).toInt();
        items = m_sda->execute("SELECT * from items ORDER BY datefield");
        qDebug()<< "the ID" << items;
        // Load all the locations from the database.
        foreach( const QVariant& temp, items.value() ) {
            Location *p;
            if (loadLocation(temp.value(), p)) {
                model->insert(p);
                loadedCount++;
            }
        }
        return loadedCount;
    }
    

    Any help will be loved and marked solutions.

    -Thanks in advance

    I was wrong about executeAndWait(). Somehow, I decided that you use the SqlConnection object, but seems his SqlDataAccess. So disregard my previous post. Keep your execute method, but you must change your code to something like this:

    QVariant endID = m_sda->execute("select max(customerID) as m from items");
    
    QVariantList vlist = endID.value();
    QVariantMap vmap = vlist.first().toMap();
    
    lastID = vmap["m"].toInt(&ok);
    

    So I changed your SQL query slightly and added "that m" so I will have something to refer later.

    Then I cast QVariantList because it is where are the results.

    Then because we know its going to be the only record, I took the 1st element in the list and converted to QVariantMap.

    Last step is to get the maximum.

    Should work this time

  • Find the minimum value in digital array that is greater than 0

    So far I have;

    $pfpp = min ($pflist);

    $pflist is the array of digital values and contains about 0.

    I need to change to $pfpp = min ($pflist); to return the lowest number which is greater than zero.

    I am stuck, can anyone help?

    Thank you

    Change the values in the table so I can't sort them in ascending order.

    Of course you can.  Or you can copy the table into a temporary array.

    $temp = $pflist;

    sort ($temp, SORT_NUMERIC)

    foreach ($temp as $value) {}

    If $value > 0; $number = $value; break;

    }

    echo "entry of zero smaller in pflist is $number";

  • How to set the minimum value for the division based on the metric of Super?

    I want to create the Super metrics include:

    (Data reading KB store / writing KB) * 100

    To get an understanding of the relationship between reads and writes.   However, this equation will always climb 0 if a number is 0.

    Is there a way to say "if read = 0 then read = 1 ' so that the equation will not evaluate to 0?

    Thank you

    -MattG

    There is no 'if' statement... but thought that you can add a (metric + 0.0001) which should not be 0

  • PSE8 - "date taken" set a fixed value for each edited image

    I've been monkeying with PSE8 for 6 months or more - not using the Organizer, but straight in the edition.

    In general, I'll create a template to a certain size (e.g., 1800 x 1200 pixels for printing 6 x 4 photos) and place an image on the template.

    After editing, I'll save the file under a new name in a new folder... and have noted recently that the "Date" property changed to exactly the same value for each image editing. 25/09/2010... Maybe it was the date of installation, I am not sure.

    In any case - it of annoying and has been touching to find help (which makes sense) online.

    Thanks in advance for any help you can give me.

    Possibly the date the template was created? PSE respects the camera EXIF data and always displays the date taken, but for digital images and new documents created in the program, it will use the file date.

Maybe you are looking for

  • Marvel sim contacts 1 HP slate tab 6

    I would like to know how to delight unnecessary phone contacts on the sim 1 of my hp slate 6 voice tab

  • generation of signals USB-6009

    Hello!! Can someone suggest me how to generate a pulse of 3V/0V to output pin (a01) to change the transistor... requirement is: 1ms - 3V and 400ms-0V permanently... With the help of NOR-USB-6009 Thanks in advance!

  • Incomplete or empty Web page

    I am a person older and not very computer savy (wanted to get that out of the way). Sometimes when I connect with a website, the page is empty or incomplete and I get the message 'error on page' with a yellow triangle and an exclamation point. I chec

  • By default the enlargement of photos when it is attached to the email

    When you attach a picture of the pictures to emails folder, the photo is automatically enlarged to several times the size of the screen.  This happens with photographs taken by several different cameras and on two different mail servers.  Can I do ph

  • Change NCO back to JPEG?

    I can't open the images of the NCO after saving JPEG I run Windows 7 Home Premium - can someone