Get only one row for each kind of a column

hi there!
i have a little problem.
I have a table with 10 columns. One of them has repeated values. My goal is to get all the rows with this column only one time for each values that it has.
Ex:
Col1 Col2 Col3
A A A
B B B
C A C
D C D
Column 2 has repeated values. My goal is to get:
A A A
B B B
D C D
Only one time each value of column 2.
Thanks guys! ;)

SQL>  CREATE TABLE Tbl (col1 VARCHAR2(1),col2 VARCHAR2(1),col3 VARCHAR2(1));
Table created.
SQL> INSERT INTO Tbl VALUES ('A','A','A');
1 row created.
SQL>              INSERT INTO Tbl VALUES ('B','B','B');
1 row created.
SQL>              INSERT INTO Tbl VALUES ('C','A','C');
1 row created.
SQL>              INSERT INTO Tbl VALUES ('D','C','D');
1 row created.
SQL> commit;
Commit complete.
SQL> SELECT * FROM tbl t1
  2  WHERE
  3  rowid=(SELECT min(rowid)
  4         FROM tbl t2
  5         WHERE t1.col2=t2.col2);
C C C
A A A
B B B
D C D
SQL> SELECT * FROM tbl t1
  2  WHERE
  3  rowid=(SELECT max(rowid)
  4         FROM tbl t2
  5         WHERE t1.col2=t2.col2);
C C C
B B B
C A C
D C DEdited by: Saubhik on Aug 3, 2010 1:31 AM

Similar Messages

  • Multiple parameters one row for each record

    I have this query I want the user to be able to allow the user to enter multiple MATL_CODE_MOD as a parameters, the problem is that the GURMAIL table have multiple records one for each GURMAIL_MATL_CODE_MOD, so it will give me duplicates.. How I can code this, so I can allow the user to enter multiple MATL_CODE_MOD codes, and have only one row for each record...
    and GURMAIL_MATL_CODE_MOD in ('8IBC','8IBD')
    select
    spriden_id,        
    spbpers_name_suffix   name_suffix,
    spbpers_name_prefix   name_prefix,
    spriden_last_name     last_name,
    spriden_first_name    first_name,
    spriden_mi            mi,
    srbrecr_term_code,
    srbrecr_majr_code,
    srbrecr_program_1,
    saturn_midd.utlq.f_matl_code_type(srbrecr_pidm)
    FROM
    saturn.srbrecr,
    saturn.spriden,
    saturn.spbpers,
    SATURN.SPRADDR,
    general.gurmail
    WHERE
    spriden_pidm = srbrecr_pidm
    and gurmail_pidm = spriden_pidm
    AND spriden_pidm = spraddr_pidm 
    --and srbrecr_term_code = decode(p_term  ,'%',SRBRECR_TERM_CODE,p_term)
    and spbpers_pidm = spriden_pidm
    and spriden_change_ind is null
    --and gurmail_matl_code_mod
    and SRBRECR_PROGRAM_1 = 'CMQ'
    and GURMAIL_MATL_CODE_MOD in ('8IBC','8IBD')
    --AND SPRADDR_ATYP_CODE = 'CM'
    AND SPRADDR_STREET_LINE1 IS NOT NULL;

    Hi,
    SELECT DISTINCT ...will keep duplicate rows out of the result set.
    Depending on your data, another possibility might be to not join the table that contains GURMAIL_MATL_CODE_MOD. Do an EXISTS sub-query on that table instead.
    If you need more help, post some sample data from all the tables, and the results you want from that data.
    Simplify, if possible, You can probably post a problem with 2 or 3 tables, each with 2 or 3 columns, that will have the same answer.
    Edited by: Frank Kulash on Apr 22, 2009 2:28 PM

  • Getting the first row for each group

    Hi Everyone,
    I have a query which returns a number of rows, all of which are valid. What I need to do is to get the first row for each group and work with those records.
    For example ...
    client flight startairport destairport stops
    A fl123 LGW BKK 2
    A fl124 LHR BKK 5
    B fl432 LGW XYZ 7
    B fl432 MAN ABC 8
    .... etc.
    I would need to return one row for Client A and one row for Client B (etc.) but find that I can't use the MIN function because it would return the MIN value for each column (i.e. mix up the rows). I also can use the rownum=1 because this would only return one row rather than one row per group (i.e. per client).
    I have been investigating and most postings seem to say that it needs a second query to look up the first row for each grouping. This is a solution which would not really be practical because my query is already quite complex and incorporating duplicate subqueries would just make the whole thing much to cumbersome.
    So what I really new is a "MIN by group" or a "TOP by group" or a "ROWNUM=1 by group" function.
    Can anyone help me with this? I'm sure that there must be a command to handle this.
    Regards and any thanks,
    Alan Searle
    Cologne, Germany

    Something like this:
    select *
    from (
       select table1.*
       row_number() over (partition by col1, col2 order by col3, col4) rn
       from table1
    where rn = 1In the "partition by" clause you place what you normally would "group by".
    In the "order by" clause you define which will have row_number = 1.
    Edit:
    PS. The [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#i81407]docs have more examples on using analytical functions ;-)
    Edited by: Kim Berg Hansen on Sep 16, 2011 10:46 AM

  • How can I have one row for each object?

    Post Author: farnaz
    CA Forum: WebIntelligence Reporting
    I have 3 objcts that one of them is ID and second one is internal code and the third one is quantity.There is more than one value for each ID (becouse of internal code).I want to create a report based on ID and quantity (not based on internal code).I make a break on ID but the result shows me more than one row for each ID.so how can i have just one row for each ID?
    another question:
    how can I post screen shot of the results to my messag in forum?

    Post Author: jsanzone
    CA Forum: WebIntelligence Reporting
    farnaz:
    Have you tried to omit "internal code" from your grid?  In normal circumstances, if you have "ID" and "Quantity" on the grid, then WebI will on its own summarize Quantity based on ID, however, this is provided that Quantity has been set up as a measure (or metric).  The quickest way to tell if Quantity is a metric or not is to observe the color of its icon when you look at it in the data panel.  If it is a purple (or sometimes appears as pink or fuscia) dot, then it's a measure, but if it is a blue box then it is a dimension.  If you need Quantity as a measure then this will have to be modified at the universe (make it look like "sum(Quantity)" in the select phase of the object, and insure the object is defined as a number....

  • Display only one row for distinct columns and with multiple rows their valu

    Hi,
    I have a table having some similar rows for some columns and multiple different rows for some other columns
    i.e
    o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
    9825000111 01-jan-06 'a' 980515464 01-feb-06 c
    9825000111 01-jan-06 'a' 991543154 02-feb-06 d
    9825000111 01-jan-06 'a' 154845545 10-mar-06 a
    What i want is to display only one row for above distinct row along with multiple non distinct colums
    ie
    o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
    9825000111 01-jan-06 'a' 980515464 01-feb-06 c
    991543154 02-feb-06 d
    154845545 10-mar-06 a
    regards,
    Kumar

    Re: SQL Help

  • How do I program a NI 6602 card to send trigger pulses, one at each output port, triggered by an input trigger signal, using only one counter for each output port?

    Hello,
    I have managed to program a NI 6602 card in LabView to send pulses on three different output ports, one pulse on each output port (with individually chosen delays) for each input trigger pulse coming on a separate input port. It is the DAQmx Create Channel (CO-Pulse Generation-Time)-VI that I have used for this, see attached code. However, this VI controls both pulse delay and pulse width, and therefore uses two counters for each output port (although you only specify one counter in the VI input signals), as I understand.
    In my application though, I only need to have the delay chosen, the pulse width can be arbitrarily short, and thus I should only need one counter for each output port. How do I accomplish to program this in LabView?
    Best regards,
    Claes
    Attachments:
    Configure Side Camera Flash 1 Triggering.vi ‏47 KB

    Well you're welcome to do that--it will work just fine as long as you are configuring a start trigger.
    <rant>
    However, personally I really don't like putting multiple counter outputs in the same task.  I have seen so many people assume that the counter outputs would be synchronized due to having them in the same task when this is not the case (you need to configure a start trigger in order to synchronize the counter outputs even if they are in the same task).  This is the only case I can think of where multiple channels in a DAQmx task are not automatically synchronized.
    As an example:
    Running this on my PCIe X Series gives a measured 2 edge separation of 1 ms + {7.78 us - 10.11 us}.  This would likely be much worse on a bus with more latency (e.g. USB).
    The resulting output is close enough to what you might expect that it might go unnoticed, but really these counter outputs are not synchronized and it would be easy to glance at the code and not even think twice about it.  For the small amount of extra work on my end to create a separate task for each counter, it really clears up some ambiguity about what the counters are actually doing.  For me it's worth it.
    So again, for your case there really isn't a problem with having the counters in the same task since you are using an external start trigger anyway.  I have just gotten in the habit of avoiding doing this.
    </rant>
    Best Regards,
    John Passiak

  • Get only one record for an id for a date if multiple record exists

    Hi,
    I need help with below mentioned scenario.
    DB Version: 11.2.0.3.0.
    Requirement:
    Fetch account records that were created after last run of program
    Get latest record for an account on a given date if there are multiple records for same account.
    If there is a gap of more than 1 day from last run of program, then get latest record for an account for each date if there are multiple records for same account.
    Create table t_test
      Id           number not null,
      cust_id      number not null,
      cust_Acct_id number not null,
      ins_date     date   not null
    insert into t_test values
    (1, 12345, 678905, to_date('05/31/2012 12:05:10 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (2, 12345, 678905, to_date('05/31/2012 05:25:46 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (3, 12345, 678905, to_date('05/31/2012 11:48:00 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (4, 12345, 678905, to_date('06/01/2012 12:05:10 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (5, 12345, 678905, to_date('06/01/2012 05:25:46 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (6, 12345, 678905, to_date('06/01/2012 11:48:00 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (7, 12345, 678905, to_date('06/02/2012 12:05:10 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (8, 12345, 678905, to_date('06/02/2012 05:25:46 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (9, 12345, 678905, to_date('06/02/2012 11:48:00 PM','MM/DD/YYYY HH:MI:SS PM'));
    create table t_log
      id            number not null,
      prgrm_id      number not null,
      last_run_date date   not null
    insert into t_log values
    (1,1009,to_date('5/30/2012 07:05:12 AM','MM/DD/YYYY HH:MI:SS PM'));Result required:
    id cust_id cust_acct_id ins_date
    3 12345 678905 '05/31/2012 11:48:00 PM'
    6 12345 678905 '06/01/2012 11:48:00 PM'
    9 12345 678905 '06/02/2012 11:48:00 PM'
    I tried below sql but it will return only id 9 record.
    select
        id,
        cust_id,
        cust_acct_id,
        ins_date
    from
        select
            id,
            cust_id,
            cust_acct_id,
            ins_date,
            row_number() over (partition by cust_acct_id order by ins_date desc) rn
        from
            t_test t
        where
            t.ins_date > (
                          select
                              last_run_date
                          from
                              t_log l
                          where
                              l.prgrm_id = 1009
    where rn = 1;Thanks in advance.

    Try:
    SQL> select
      2      id,
      3      cust_id,
      4      cust_acct_id,
      5      ins_date
      6  from
      7      (   
      8      select
      9          t.id,
    10          t.cust_id,
    11          t.cust_acct_id,
    12          t.ins_date,
    13          row_number() over (partition by cust_acct_id, trunc(ins_date) order by ins_date desc) r
    n
    14      from
    15          t_test t
    16      ,   t_log l 
    17      where
    18          t.ins_date >= l.last_run_date
    19      and l.prgrm_id = 1009
    20      )
    21  where rn = 1;
            ID    CUST_ID CUST_ACCT_ID INS_DATE
             3      12345       678905 31-05-2012 23:48:00
             6      12345       678905 01-06-2012 23:48:00
             9      12345       678905 02-06-2012 23:48:00But I now see that Bob already nailed it, while I was testing it ;)

  • Is it possible to require a security password to be entered only one time for each instance of a pdf

    How I imagine it to work:
    I receive a secured pdf; I open it and enter the password. I am able to open the pdf again without password restrictions. If I copy the pdf I am required to enter a password the copy

    Passwords are set when the document is created in Acrobat, and as far as I know they MUST be applied each and every time the document is opened. In other words, it doesn't and can't use cookies to remember that you've already entered it, because there are none in the OS.

  • Query for one row of each distinct column value

    lets say theres table employee with columns name, id, and title. How do you get one row for each distinct title. Whatever row it is doesnt matter as long as your result set covers every possible employee title. How can I do this? thanks

    Hi,
    I think you're asking about a Top-N Query .
    Since you didn't post a version of your table, I'll use scott.emp to illustrate.
    The following query shows exactly one row of output for each distinct job:
    WITH        got_r_num         AS
         SELECT     empno, ename, job
         ,     ROW_NUMBER () OVER ( PARTITION BY  job
                                   ORDER BY          ename
                                 ) AS r_num
         FROM    scott.emp
    SELECT     empno, ename, job
    FROM     got_r_num
    WHERE     r_num     = 1
    ;Output:
    `    EMPNO ENAME      JOB
          7902 FORD       ANALYST
          7876 ADAMS      CLERK
          7698 BLAKE      MANAGER
          7839 KING       PRESIDENT
          7499 ALLEN      SALESMANThe rows you see are actual rows from the table, not aggregates. That is, you can be certain that there is a row in the table with empno=7902, ename='FORD' and job='ANALYST'.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    If the desired results are not unique, that is, if you'd be equally satisfied with a number of different result sets, then post a couple of examples from the same sample data.

  • Oracle database link to MySQL select only one row

    Hello,
    I have created a connection from the Oracle batabase 11.2 to a MySQL database via database link. The following statement shows, that 35 rows are in the mySQL table:
    SQL>  select count(*) from "main_pages"@MOREWEB;
      COUNT(*)
            35
    But a normal select statement only return 1 row.
    SQL> select "subject" from "main_pages"@MOREWEB;
    subject
    Übersicht: Referenzen
    I am using the mysql-connector-odbc-3.51.30-winx64 driver. A newer version cann't be installed because on Windows Server 2008 R2 I get an error with an missing dll-file. The DataDirect-ODBC-driver is not possible, because we like to use the free MySQL-database an DataDirect only support the enterprise edition.
    I also have tried to limit the HS_OPEN_CURSORS or dont limit the HS_FDS_FETCH_ROWS, but there is no difference in the result. I always get only one row.
    HS Init.ora
    # This is a sample agent init file that contains the HS parameters that are
    # needed for the Database Gateway for ODBC
    # HS init parameters
    HS_FDS_CONNECT_INFO = moreweb
    HS_FDS_TRACE_LEVEL = ON
    HS_FDS_FETCH_ROWS=1
    # Environment variables required for the non-Oracle system
    #set <envvar>=<value>
    HS tracefile
    Oracle Corporation --- MITTWOCH   NOV 05 2014 13:56:22.066
    Heterogeneous Agent Release
    11.2.0.1.0
    Oracle Corporation --- MITTWOCH   NOV 05 2014 13:56:22.066
        Version 11.2.0.1.0
    HOSGIP for "HS_FDS_TRACE_LEVEL" returned "ON"
    HOSGIP for "HS_OPEN_CURSORS" returned "50"
    HOSGIP for "HS_FDS_FETCH_ROWS" returned "1"
    HOSGIP for "HS_LONG_PIECE_TRANSFER_SIZE" returned "65536"
    HOSGIP for "HS_NLS_NUMERIC_CHARACTER" returned ".,"
    HOSGIP for "HS_KEEP_REMOTE_COLUMN_SIZE" returned "OFF"
    HOSGIP for "HS_FDS_DELAYED_OPEN" returned "TRUE"
    HOSGIP for "HS_FDS_WORKAROUNDS" returned "0"
    HOSGIP for "HS_FDS_MBCS_TO_GRAPHIC" returned "FALSE"
    HOSGIP for "HS_FDS_GRAPHIC_TO_MBCS" returned "FALSE"
    HOSGIP for "HS_FDS_RECOVERY_ACCOUNT" returned "RECOVER"
    HOSGIP for "HS_FDS_TRANSACTION_LOG" returned "HS_TRANSACTION_LOG"
    HOSGIP for "HS_FDS_TIMESTAMP_MAPPING" returned "DATE"
    HOSGIP for "HS_FDS_DATE_MAPPING" returned "DATE"
    HOSGIP for "HS_FDS_CHARACTER_SEMANTICS" returned "FALSE"
    HOSGIP for "HS_FDS_MAP_NCHAR" returned "TRUE"
    HOSGIP for "HS_FDS_RESULTSET_SUPPORT" returned "FALSE"
    HOSGIP for "HS_FDS_RSET_RETURN_ROWCOUNT" returned "FALSE"
    HOSGIP for "HS_FDS_PROC_IS_FUNC" returned "FALSE"
    HOSGIP for "HS_FDS_REPORT_REAL_AS_DOUBLE" returned "FALSE"
    using mpgw as default value for "HS_FDS_DEFAULT_OWNER"
    HOSGIP for "HS_SQL_HANDLE_STMT_REUSE" returned "FALSE"
    SQL text from hgopars, id=1, len=36 ...
         00: 53454C45 43542043 4F554E54 282A2920  [SELECT COUNT(*) ]
         10: 46524F4D 20606D61 696E5F70 61676573  [FROM `main_pages]
         20: 60204131                             [` A1]
    Deferred open until first fetch.
    Performing delayed open.
    SQL text from hgopars, id=1, len=40 ...
         00: 53454C45 43542041 312E6073 75626A65  [SELECT A1.`subje]
         10: 63746020 46524F4D 20606D61 696E5F70  [ct` FROM `main_p]
         20: 61676573 60204131                    [ages` A1]
    Deferred open until first fetch.
    Performing delayed open.
    Please can help me someone.
    Thanks.
    Bianca

    mxallen wrote:
    Bianca,
    If you log directly into MySQL and issue the same query (select "subject" from "main_pages";) what data is returned?
    I looks to me that you count is the number of rows in the entire table "main_pages"
    while you select is for the data in the "subject" column only.
    This seems to indicate that you have just one row in that subject column.
    Regards,
    Matt
    WHAATT?
    What do you mean by "just one row in that subject column"?
    That makes no sense at all.  A row is a row.  A column is a part of a row.  All rows have all columns, though not all columns of all rows will necessarily have an assigned value.  Lacking a WHERE clause to filter rows, any SELECT should return all rows.

  • Comma separated column into rows for each value

    experts,
    I have a two column table. The second column has comma separated string values. How can I put the values separate for each comma separated and make one row for each value?
    example,
    column1 |   StringColumn
    s1          |   test, joy, happy
    s2          |  USA, England, India
    I want the result to be like below
    column1   |     StringColumn
    s1            |      test
    s1            |      joy
    s1            |      happy
    s2            |     USA
    s2            |     England
    s2            |     India
    thanks in advance
    ebro

    Hello ebro,
    See the following for a possible solution:
    http://gallery.technet.microsoft.com/scriptcenter/Convert-Small-CSV-Value-to-ffc142ff
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • If you registrate one Apple ID for each iPhone/iPad, you'll get 5GB on iCloud for each Apple ID, right? I have two iPhones and one iPad  with the same Apple ID, why can't I get 5 GB fo each of them?

    If you registrate one Apple ID for each iPhone/iPad, you'll get 5GB on iCloud for each Apple ID, right? I have two iPhones and one iPad  with the same Apple ID, why can't I get 5 GB fo each of them?

    Actually, everyone missed one point, when a device is priced, the cost of icloud storage space for that device is also included in it that is why they are able to give you 5gb each for each user ID, in nutshell there is nothing free coming with apple device purchase, it is paid for.  What they are trying by giving only 5gb per user ID irrespective of the number of devices used is pure broadlight looting, they take money from you when you buy each device and give you nothing, This is a case of goods and services bought but not fully deliverd ie apple can be suied for discreminatory treatment towards it's users. I wonder why no one tried this yet in America where everyone sue everyone for petty things..... there is no one to take up this issue? . if tim got any love for the guys who shell out money for the devices his company makes, he should be implimenting this as priority before someone wake up from sleep and sue him.

  • XML DB: is it possible to get a row for each element in a container element?

    I have an XML document containing a container element (collection). If I query, using an XPath expression, the contained elements I get a row for each container element with the contained element concatenated. Is it possible to get a row for each contained element?
    I run this simple query:
    select extract(xmltype('<colors><color>Red</color><color>Green</color></colors>')
    , '/colors/color/text()').getstringval() from dual
    And get this result:
    EXTRACT(XMLTYPE('<COLORS><COLOR>RED</COLOR><COLOR>GREEN</COLOR></COLORS>'),'/COL
    RedGreen
    1 row selected.
    What I would like to have is:
    Red
    Green
    2 rows selected.
    Wishful thinking or possible? Many thanks!

    Sure. This is where our XMLSequence() function comes in. It allows you to treat the top-level nodes in a nodeset as if they were rows in a table when combined with the TABLE() operator. Here's an example.
    First, to make the SQL look a little cleaner, I like to define a function like this:
    create or replace function testdoc return xmltype as
    begin
      return xmltype('<colors><color>Red</color><color>Green</color></colors>');
    end;.
    To break out the nodeset of <color> elements as a table, we use the following query:
    select value(list_of_color_elements).extract('*/text()').getStringVal() as color
    from TABLE( XMLSequence( extract(testdoc(),'/colors/color'))) list_of_color_elements.
    Or, using the new-in-9.2 extractValue() operator so we don't have to remember the text() part:
    select extractValue( value(list_of_color_elements), '.') as color
    from TABLE( XMLSequence( extract( testdoc() ,'/colors/color'))) list_of_color_elements.
    Here the TABLE(XMLSequence(...)) combo produces a table of XMLType, with one XMLType object in each row of the table.
    In general, if the XMLType instance were coming from an XMLType table xmltab the query would look like this:
    select extractValue( value(colors), '.') as color
    from xmltab x, /* Important that this table comes earlier in the FROM clause! */
         TABLE( XMLSequence( extract( value(x),'/colors/color'))) colors.
    And if the XMLType were instead in a column of XMLType named doc in a table xmltab, then we would have the syntax:
    select extractValue( value(colors), '.') as color
    from xmltab x, /* Important that this table comes earlier in the FROM clause! */
         TABLE( XMLSequence( extract( x.doc ,'/colors/color'))) colorsOnce you get the hang of it, you'll see that the combination of TABLE(XMLSequence()) to "shred" XML nodes into rows, and XMLAgg() to aggregate fragments of XML across multiple rows back into a single document, is quite powerful.

  • How do I get The ipad locked to run only one application for customers (perhaps a webapp)

    how do I get The ipad locked to run only one application for customers (just one web app, or video- instructions, or just safari). What I really want is that my customers to only use one app that has all my services. It is an interactive app so I would not like them to go surfing elsewhere while they are in my store.
    Is it possible to do this on the iPad ?

    Try this:
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    checkbox - clusters_MOD.vi ‏23 KB

  • Please help with an sql to show more than one records into single row for each student

    From the following data I would like to create an sql to get the information  as the following layout
    studentid,  firstTerm,  EnglishMark1,ScienceMark1,MathsMark1, Secondterm,EnglishMark2,ScienceMark2,MathsMark2,
    ThirdTerm,EnglishMark3,ScienceMark3,MathsMark3 // As single rows for each student
    Example
    1 First, 30,40,20,Sec,30,40,20,  simillarly next row for next row for another sudent. Please help to generate the sql for the same.
    Please help it would be very appreciate.
    With Thanks
    Pol
    polachan

    create table yourdata (studentid int, term varchar(10), section varchar(50), Mark int)
    insert into yourdata values
    (1,'First','Math',20),(1,'First','English',30),(1,'First','Science',40),
    (2,'First','Math',20),(2,'First','English',30),(2,'First','Science',40),
    (3,'First','Math',20),(3,'First','English',30),(3,'First','Science',40),
    (1,'Sec','Math',20),(1,'Sec','English',30),(1,'Sec','Science',40),
    (2,'Sec','Math',20),(2,'Sec','English',30),(2,'Sec','Science',40),
    (3,'Sec','Math',20),(3,'Sec','English',30),(3,'Sec','Science',40)
    Select studentid
    ,max(case when term='First' and section='English' Then Mark End) as EnglishMark1
    ,max(case when term='First' and section='Science' Then Mark End) as ScienceMark1
    ,max(case when term='First' and section='Math' Then Mark End) as MathMark1
    ,max(case when term='Sec' and section='English' Then Mark End) as EnglishMark2
    ,max(case when term='Sec' and section='Science' Then Mark End) as ScienceMark2
    ,max(case when term='Sec' and section='Math' Then Mark End) as MathMark2
    ,max(case when term='Third' and section='English' Then Mark End) as EnglishMark3
    ,max(case when term='Third' and section='Science' Then Mark End) as ScienceMark3
    ,max(case when term='Third' and section='Math' Then Mark End) as MathMark3
    From yourdata
    Group by studentid
    drop table yourdata

Maybe you are looking for