Help with the query to return the last possible value

Can someone please help me to create a query for the situation below?

Table: TABLEA
Columns:
FACID VARCHAR2 (10),
DEPTID VARCHAR2 (10),
CHARGENUMBER NUMBER (10)

I have the following data:

A, B, 1
A, B, 2
C, D, 3
C, D, 4

I will return the following:

A, B, 2
C, D, 4

In other words, I would return the last possible CHARGENUMBER for FACID and DEPTID.
The table has no index, and it is responsible for a worksheet in that order.

Thank you very much!

Hello

If you have a TIMESTAMP column, called entry_dt, you can use a Top - N query like this to find the last x entries.

WITH  got_rnum  AS
(
     SELECT  my_table.*
     ,     RANK () OVER (ORDER BY entry_dt DESC)     AS rnum
     FROM     my_table
)
SELECT     *     -- or list all columns except rnum
FROM     got_rnum
WHERE     rnum     <= x
;

It is very common to have a trigger to ensure that columns like entry_dt are met.

If you have only one statement that inserts with hundreds of lines, they can all have the same entry_dt. (The value of SYSTIMESTAMP is constant throughout a statement, even if it takes a few seconds).
The above query uses RANK, so if you tell him you want the last 10 entries, it can return more than 10, because it includes all lines with exactly the same entry_dt as the 10th. If you want to exactly 10 rows returned, even if there is a tie for 10th place, then use ROW_NUMBER instead of RANK; the rest of the query is the same.

Tags: Database

Similar Questions

  • Need help with the accumulation of value.

    Hello world

    My version of DB is

    BANNER

    ----------------------------------------------------------------

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi

    PL/SQL Release 10.2.0.1.0 - Production

    CORE 10.2.0.1.0 Production

    AMT for Linux: Version 10.2.0.1.0 - Production

    NLSRTL Version 10.2.0.1.0 - Production

    Please take a look at the structure of the table, some examples of values, query, and result and help out me.

    create table ppdev_own.product

    (

    number of product_id,

    sold_date date null not activate.

    activate the sold_quantity number not null,

    constraint product_pk primary key (product_id, sold_date, sold_quantity) activation

    ) ;

    insert into product (product_id, sold_date, sold_quantity) values (1000, to_date('12-NOV-2014','DD-MON-YYYY'), 100);

    insert into product (product_id, sold_date, sold_quantity) values (1000, to_date('12-DEC-2014','DD-MON-YYYY'), 150);

    insert into product (product_id, sold_date, sold_quantity) values (1000, to_date('12-JAN-2015','DD-MON-YYYY'), 200);

    insert into product (product_id, sold_date, sold_quantity) values (2000, to_date('12-NOV-2014','DD-MON-YYYY'), 120);

    insert into product (product_id, sold_date, sold_quantity) values (2000, to_date('12-DEC-2014','DD-MON-YYYY'), 170);

    insert into product (product_id, sold_date, sold_quantity) values (2000, to_date('12-JAN-2015','DD-MON-YYYY'), 220);

    insert into product (product_id, sold_date, sold_quantity) values (2000, to_date('13-JAN-2015','DD-MON-YYYY'), 100);

    -Query

    with the temp as

    (select distinct p1.product_id,

    P1.sold_date,

    P1.sold_quantity,

    Count (*) on total_occurrence (p1.product_id partition).

    ROW_NUMBER() over (partition by product_id arrested by p1.product_id) rownumber

    the product p1

    order of p1.product_id,

    P1.sold_date

    )

    Select t.product_id,

    t.sold_date,

    t.sold_quantity,

    case

    When lag (t.sold_quantity) over (partition by t.product_id of t.product_id order) is null

    then t.sold_quantity

    When t.rownumber < t.total_occurrence

    then lag (t.sold_quantity) over (partition by order of t.product_id t.product_id) + t.sold_quantity

    When t.total_occurrence = t.rownumber

    then sum (t.sold_quantity) on (t.product_id score)

    end as sold_quantity_acc

    t temp;

    Result

    PRODUCT_IDSOLD_DATESOLD_QUANTITYSOLD_QUANTITY_ACC
    1000JANUARY 12, 2015200200
    100012 DECEMBER 2014150350
    1000NOVEMBER 12, 2014100450
    2000JANUARY 12, 2015220220
    200012 DECEMBER 2014170390
    2000JANUARY 13, 2015100270 -instead of 270, he must return to 490
    2000NOVEMBER 12, 2014120610

    Please see the comment in bold and help out me. How can I maintain the continuous accumulation of value that will keep calculation of the quantity sold. Please correct me if my approach is wrong.

    Kind regards

    BS2012.

    Select product_id,

    sold_date,

    sold_quantity,

    Sum (sold_quantity) on sold_quantity_acc (partition by product_id arrested by sold_date)

    product

    PRODUCT_ID SOLD_DATE SOLD_QUANTITY SOLD_QUANTITY_ACC
    1000 12/11/2014 100 100
    1000 12/12/2014 150 250
    1000 12/01/2015 200 450
    2000 12/11/2014 120 120
    2000 12/12/2014 170 290
    2000 12/01/2015 220 510
    2000 13/01/2015 100 610

    Concerning

    Etbin

  • MY FONT SIZE HAS CHANGED WITH THE LAST UPDATE AND I CAN'T SEEM TO RETURN TO NORMAL.

    WITH THE LAST UPDATE OF THE FONT SIZE CHANGED ON MY EMAIL ACCOUNTS AND PAGES OF MY WORK.  IT OF SMALL, I CAN'T READ IT EVEN WITH GLASSES ON. IT IS MAGNIFIED 150 TIMES.  MY COMPANY, HE CHANGED THE RESOLUTION WHICH HAS CHANGED MY SIZES OF ICONS, BUT DOESN'T HAVE ANYTHING DONE TO MY FONT SIZES.  THE HAD ME ALSO DO SOMETHING WITH MICROSOFT THAT DOESN'T WORK ANYMORE.  SO THEY HAD ME CONTACT MICROSOFT WHO CAN HELP ME BECAUSE I CAN'T AFFORD TO PAY TO GET ANSWERS TO MY QUESTIONS.  I AM ALREADY 3 HOURS LATE FOR WORK IN TRYING TO SOLVE THIS PROBLEM.  CAN SOMEONE OUT THERE HELP ME?

    Hi ELLA SMITH (KELLY).

     

    Welcome to the Microsoft community forums. Please post your query and giving me the opportunity to help you.

    I'm sorry for the inconvenience caused.

    I will guide you on the issue of the police.

    (1) you are on a domain network?

    (2) the Windows updates were installed?

    (3) what happens when you try to change the font sizes, you get an error message?

    I suggest you refer to the link to verify that Windows update have been installed.

    http://Windows.Microsoft.com/en-us/Windows-Vista/see-which-Windows-updates-are-installed

    Method 1:

    You can check follow them the links below, if that helps:

    (1) change the Windows fonts

    http://windowshelp.Microsoft.com/Windows/en-in/help/bdc9d003-777b-4B1E-9664-2957f50870bd1033.mspx

    (2) fonts: frequently asked questions

    http://windowshelp.Microsoft.com/Windows/en-in/help/0caf0419-6990-45de-8D71-67f14a3ae4c71033.mspx

    (3) how to repair the operating system and how to restore the configuration of the operating system to an earlier point in time in Windows Vista

    http://support.Microsoft.com/default.aspx/KB/936212

    Method2:

    un) make system restore, choose the date where the screen resolution and the fonts were ok as your restore point.

    (b) when these updates come to install again, do only ONE AT A TIME. After each installation, check if the screen is ok, and then next update and so on.

    c) in this way, you'll be able to simply update is the cause of this problem.

    If the problem persists feel free to post us. We're here to help.

    Thank you.

  • Need help with the query using the aggregation

    If I have a table, defined as follows:

    CREATE TABLE range_test
    (
    range_id NUMBER (20) NOT NULL,
    rank of char (1) NOT NULL,
    lower_bound_of_range NUMBER (5.2) NOT NULL,
    upper_bound_of_range NUMBER (5.2) NOT NULL,
    received_date_time_stamp SYSTIMESTAMP NOT NULL DEFAULT TIMESTAMP
    );

    And I wanted to query the table to find the range associated with the last line inserted for each 'class' (for example 'A', 'B', 'C', etc.), how would I go about this?

    I want something like the following, but I know that it will not work right:

    SELECT
    grade,
    lower_bounding_of_range,
    upper_bounding_of_range,
    Max (received_date_time_stamp)
    Of
    range_test GROUP BY received_date_time_stamp;

    Thanks for your help... I am frustrated with this one and I think that it should be possible without having to use the PL/SQL (i.e. the functions of SQL aggregation or subqueries should work).

    Perhaps something along the lines of...

    SQL> ed
    Wrote file afiedt.buf
    
      1  select deptno, empno, ename, hiredate
      2  from emp
      3* order by deptno, empno
    SQL> /
    
        DEPTNO      EMPNO ENAME      HIREDATE
    ---------- ---------- ---------- --------------------
            10       7782 CLARK      09-JUN-1981 00:00:00
            10       7839 KING       17-NOV-1981 00:00:00
            10       7934 MILLER     23-JAN-1982 00:00:00
            20       7369 SMITH      17-DEC-1980 00:00:00
            20       7566 JONES      02-APR-1981 00:00:00
            20       7788 SCOTT      19-APR-1987 00:00:00
            20       7876 ADAMS      23-MAY-1987 00:00:00
            20       7902 FORD       03-DEC-1981 00:00:00
            30       7499 ALLEN      20-FEB-1981 00:00:00
            30       7521 WARD       22-FEB-1981 00:00:00
            30       7654 MARTIN     28-SEP-1981 00:00:00
            30       7698 BLAKE      01-MAY-1981 00:00:00
            30       7844 TURNER     08-SEP-1981 00:00:00
            30       7900 JAMES      03-DEC-1981 00:00:00
    
    14 rows selected.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  select deptno, empno, ename, hiredate
      2  from (
      3        select deptno, empno, ename, hiredate
      4              ,row_number() over (partition by deptno order by hiredate desc) as rn
      5        from emp
      6       )
      7  where rn = 1
      8* order by deptno, empno
    SQL> /
    
        DEPTNO      EMPNO ENAME      HIREDATE
    ---------- ---------- ---------- --------------------
            10       7934 MILLER     23-JAN-1982 00:00:00
            20       7876 ADAMS      23-MAY-1987 00:00:00
            30       7900 JAMES      03-DEC-1981 00:00:00
    
    SQL>
    
  • When I burn CD for my use on the computer, sometimes the order of the songs are returned, starting with the last song first.

    * Original title: Windows Media player

    When I burn CD for my use on the computer, sometimes the order of the songs are returned, starting with the last song first.  This is the CD, or I do something wrong?  This isn't an ongoing problem... most of the time it's ok.  Can I change the order manually. If Yes, where and how.

    Thank you

    Lee

    Lee - there are a number of possibilities. First of all, it depends whether you burn audio disks or data - if they are audio discs, you can check and rearrange the order of songs in the burn list - if necessary - before you start burning. If you drag multiple files to the burn list quite often the last track you clicked on will go upward, so I wonder if it is what can happen. Back with a little more detail if I not quite correctly interpreted the problem. Best regards, Ric.

  • The latest version of Lr does not work with the last WIN10, I need help

    The latest version of Lr does not work with the last WIN10, I need help

    Finally I understand it by putting at level c ++ Redistributable Package, surprisingly it works. Anyway, thanks for your answer...

    Good day!

  • Help with the query to select only one record from the result set in double

    Hello

    Please help with the query. Version of Oracle database we use is 10g R2.

    I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec

    ID
    Org
    DF
    Sec Sub-Sec

    (163)CQCPDMCPDMHD(163)PCENGENGENG(163)CQASICASICIS8888TSTACTACTAC(163)TSHEHESW6789CQINFOINFOFOS6789PCSECSYSSECSYSINFO16789TSSECSYSSECSYSINFO29009PCBMSBMSBMS1

    My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.

    ID
    DSB

    DF
    SEC
    Sub-Sec
    (163)CQCPDMCPDMHD8888TSTACTACTAC6789CQINFOINFOFOS9009PCBMSBMSBMS1


    Thank you

    Orton

    Hello

    This sounds like a job for ROW_NUMBER:

    WITH got_r_num AS

    (

    SELECT id, DSB, df, s, sub_sec org

    ROW_NUMBER () OVER (PARTITION BY ID.

    ORDER BY org

    ) AS r_num

    OF view_x

    )

    SELECT id, DSB, df, sub_sec s,

    OF got_r_num

    WHERE r_num = 1

    ;

    He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data.  (I know that you said that you were a view selection.  Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.  (I didn't quite understand the explanation above.  I don't know why you want to

    ID ORG DF DRY SUB_SEC

    --      ---     --      ---     -------

    1234 CQ DPRK DPRK HD

    and is not

    1234 IS CQ ASIC, ASIC

    or

    TS 1234 IT IT SW

    or

    1234 CQ ASIC ASIC HD

    )
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • need help with the query, thx

    Hello
    I need a little help with the query I have to write;
    the table has 4 columns:
    col1               col2         col3       col4
    emp_name     empl_id    salary      year
    
    content of data:
    
    col1               col2         col3       col4
    smith             12           1200      1999
    smith             12           1340      2000
    smith             12           1500      2001
    jones             13           1550      1999 
    jones             13           1600      2000
    aron              14           1200      2002
    what I am asking is the following result: salary according to the latest available year
    i.e.
    smith         12         1500        2001
    jones         13         1600        2000
    aron          14         1200        2002
    ID appreciate some guidance on how to achieve
    Thank you
    Rgds
    select *from
    (select col1, col2,col3, col4,row_number() over(partition by col1 order by col4 desc)  rn  from 
    ) where rn=1
    
  • locked out of my error of the portable computer, your PC is in offline mode. Please sign in with the last password used on this PC"

    OT: locked out of my laptop.

    Hello, I have an Asus with Windows 8, and last night my friend locked me out of my laptop by pressing on enter far too often. Now I can not connect on my laptop. Whenever I get my password it says "your PC is offline.". Please sign in with the last password used on this PC"and I really need to get inside because I have a great duty that I have to finish and return. I really need help.

    Hello Tiana,

    Thanks for posting your query in Microsoft Community Forum.

    Of course, I understand the feeling of being locked out of computer especially when you have something important lined up.

    In this scenario, you perform Refresh if you have Windows 8 DVD with you.

    How to refresh, reset or restore your PC

    Warning: Apps that you have installed Web sites and DVD will be removed. The applications provided with your PC and applications that you have installed in the Windows store will be resettled. Windows puts a list of apps removed on your desktop after you refresh your PC.

    In case you don't have a disc, you can contact Asus that can help reset the computer to factory settings.

    Contact us - Asus

    Hope this information is useful. Please feel free to answer in the case where you are facing in the future other problems with Windows.

    Thank you.

  • Unable to connect when I try to sign, he said: "your computer is offline. Please sign in with the last password used on this computer. »

    Original title: Unable to connect

    Ok. So I'm having a few problems to connect to my computer windows laptop 8. I have reset my password like 5 times, restarted my computer over the same period of time, and I can not even sign. When I try to sign, it says: "your computer is offline. Please sign in with the last password used on this computer. "Well, I don't know what was the last password. I'm sure that the last time I registered on my laptop, I used the PIN that I used to have for her. The only reason why I changed it was because I wanted it to be more difficult to get into my PC. But I wanted more difficult for other people, not more difficult for me. Can someone help me with this please?

    Hi Arianna,.

    Thanks for posting your query on the Microsoft Community.

    I understand the inconvenience caused to you. I'll be happy to help you with your problem.

    I suggest you refer to the suggestion given in the thread and check out them below if it can help solve your problem:

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_8-security/whats-the-fix-for-your-PC-is-offline-please-sign/fd7dc731-6e23-4044-BFEE-dd8fbb42fc32

    Let us know the status of the issue. We will be happy to help you further.

    Thank you.

  • Photoshop no longer works with the last update

    It is constantly freezing and I can't get any work done at all. Does anyone else have this problem? It began with the last update CC. I hate that we are paying for a product that is not 24/7 support.

    Hi Ktgilead,

    Allows you to restore Preferences quickly by using a keyboard shortcut: press and hold Alt + Ctrl + Shift (Windows) or Option + command + shift (Mac OS) when you start Photoshop. You are prompted to Remove thesettings. New Preferences files are created the next time you start Photoshop.

    * Please take a return for all stocks custom or preset that you have in Photoshop, they may be lost

    If it does not can provide us with information, it's that a computer mac or windows that you use.

    Copy and paste the system information that can be found under help > information system (in Photoshop menu bar)

    Thank you

  • Need help with the condition join in SQL

    Hi all -

    I need to ask for help with this query:

    Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));

    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ("Column3", 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('column4', 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ("column1", "table2", 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column2', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', "Column3", 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column4', 'varchar2')
    Commit;

    Create table all_cons_columns_test (varchar2 (30) from table_name, column_name varchar2 (30), constraint_name varchar2 (30))

    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "primary")
    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "secondary")
    Commit;

    This is my query and the current result:

    Select u.table_name, u.column_name, c.constraint_name
    Of user_tab_col_test u
    Outer join all_cons_columns_test c left
    On (u.table_name = c.table_name
    AND U.COLUMN_NAME = C.COLUMN_NAME
    AND C.CONSTRAINT_NAME IN ('main'))
    order of U.table_name, U.COLUMN_NAME;

    TABLE_NAME COLUMN_NAME, CONSTRAINT_NAME
    ------------------ --------------------- ----------------------------
    Table1 primary Column1
    Table1 Column2
    Table 1 Column3
    Table2 Column1
    Table2 Column2


    Three questions:
    (1) I don't want to return results where table_name = "table1". I can't get this to work.
    (2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.
    (3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?

    Any advice/suggestions are appreciated-
    John

    Published by: user703358 on January 11, 2013 20:57

    Published by: user703358 on January 11, 2013 21:48

    Hi, John,.

    user703358 wrote:
    Hi all -

    I need to ask for help with this query:

    Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));

    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')...

    Thanks for posting the CREATE TABLE and INSERT.
    It is more useful if you post the code that can be run without modification. You did not semicolons after INSERTION instructions.

    Three questions:
    (1) I don't want to return results where table_name = "table1". I can't get this to work.

    What have you tried? Post your best attempt.
    Here's one way:

    SELECT    u.table_name
    ,        u.column_name
    ,        c.constraint_name
    FROM             user_tab_col_test      u
    LEFT OUTER JOIN  all_cons_columns_test  c
                            ON    u.table_name     = c.table_name
                   AND   u.column_name     = c.column_name
                   AND   c.constraint_name IN ('primary')
    WHERE       u.table_name     = 'table1'          --  *****  NEW  *****
    ORDER BY  u.table_name
    ,            u.column_name
    ;
    

    You would not put this condition in the clause; who controls what is considered as a match between the tables, and "u LEFT OUTER JOIN c" means show all lines of u, even if they do not have a match in the c.

    (2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.

    Basically, this application is very well.
    It displays all the columns of user_tab_col_test; missing data_type. Just add u.data_type to the SELECT clause, or change the SELECT clause

    SELECT    u.*
    ,         c.constraint_name
    

    (3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?

    Do you mean "" * add * one-third * column * to all_cons_columns_test '? "
    It depends on what results you want. Post new CREATE TABLE and INSERT and instructions the results you want new data.
    Most likely, the basic structure of what you've written will remain exactly the same.

  • Help with the session variable PHP CS5.5 - Please

    Hi all

    I am needing a little help with the help of a session variable, and I hope someone can point me in the right direction.

    I created a PHP page that uses the Dreamweaver 'User authentication' feature and the basics of this works very well, to direct a user to the correct page depending on whether they are or are not a valid user. I want to customize the page 'user valid' with people, user name entered in the authentication of the user table... a seemingly simple task using a session variable, but I just seem not to be able to make it work!

    The generated code for the AU on page 1 is the following:

    <? PHP

    Validate request to connect to this site.

    If (! isset {})

    session_start();

    }

    $loginFormAction = $_SERVER ['PHP_SELF'];

    If (isset($_GET['accesscheck'])) {}

    $_SESSION ['PrevUrl'] = $_GET ['accesscheck"];

    }

    If (isset($_POST['txtfirst_name'])) {}

    $loginUsername = $_POST ['txtfirst_name'];

    $password = $_POST ['txtsurname'];

    $MM_fldUserAuthorization = "";

    $MM_redirectLoginSuccess = "member_update.php";

    $MM_redirectLoginFailed = 'login.php ';

    $MM_redirecttoReferrer = false;

    @mysql_select_db ($database_panto, $panto);

    $LoginRS__query = sprintf ("SELECT firstname, name OF web_access WHERE firstname = %s AND family name = %s",

    GetSQLValueString ($loginUsername, "text"), GetSQLValueString ($password, "text"));

    $LoginRS = mysql_query ($LoginRS__query, $panto) or die (mysql_error ());

    $loginFoundUser = mysql_num_rows ($LoginRS);

    If {($loginFoundUser)

    $loginStrGroup = "";

    If (via PHP_VERSION > = 5.1) {session_regenerate_id (true) ;} else {session_regenerate_id() ;}

    Declare two session variables and assign them

    $_SESSION ['MM_Username'] = $loginUsername;

    $_SESSION ["MM_UserGroup"] = $loginStrGroup;

    If (isset($_SESSION['PrevUrl']) & & false) {}

    $MM_redirectLoginSuccess = $_SESSION ["PrevUrl"];

    }

    Header ("Location:".) $MM_redirectLoginSuccess);

    }

    else {}

    Header ("Location:".) $MM_redirectLoginFailed);

    }

    }

    ? >

    First of all, the text highlighted in red above seems to be setting the session variable that I need. Is this correct?

    If so, what is the code that I need to put on page 2 to use this session variable? or

    I have to do something else on the page 1 to correctly assign the session variable?

    Would be very grateful for your expertise

    Mark

    It seems that you put the columns incorrectly in the user authentication server behavior. This is the SQL query that checks the credentials of the user:

    $LoginRS__query = sprintf ("SELECT firstname, name OF web_access WHERE firstname = %s AND family name = %s",

    GetSQLValueString ($loginUsername, "text"), GetSQLValueString ($password, "text"));

    You are looking for first name and last name, while you should look for the user name and password of the user.

    $_SESSION ['MM_Username"] is a session variable that stores the login name of the user. To use it in a page, all that is needed is the page start with session_start(). You can then echo the value to display.

    If you want to display the person's true name, you must create a recordset in the second page, use of $_SESSION ['MM_Username'] to search for the first name and the patronymic. Alternatively, you can change the code like this (I copied only part of it):

    $LoginRS__query = sprintf ("SELECT firstname, surname OF web_access WHERE firstname = %s AND password is %s",

    GetSQLValueString ($loginUsername, "text"), GetSQLValueString ($password, "text"));

    $LoginRS = mysql_query ($LoginRS__query, $panto) or die (mysql_error ());

    $loginFoundUser = mysql_num_rows ($LoginRS);

    If {($loginFoundUser)

    $loginStrGroup = "";

    $row = mysql_fetch_assoc ($LoginRS);

    $_SESSION ['full_name'] = $row ["FirstName"]. ' ' . $row ['name'];

    If (via PHP_VERSION > = 5.1) {session_regenerate_id (true) ;} else {session_regenerate_id() ;}

    Declare two session variables and assign them

    $_SESSION ['MM_Username"] = $loginUsername;

    $_SESSION ["MM_UserGroup"] = $loginStrGroup;

    You can then use $_SESSION ['full_name'] in a page which begins with session_start().

  • need help with the Update statement

    Hello
    I received a question in a course and I tried my best to respond, and now my brain is giving. I would really appreciate help with the update statement. I don't mind if you do not validate a solution, a little nudge in the right direction would be really useful. I'll post that I got.

    THE QUESTION
    / * For these agents disabled on more than seven missions, change their date of deactivation of the first date of deactivation of all the agents that have been activated in the same year as the agent that you update currently.
    */

    I have it divided into parts, here is my select statement to agents disabled on more than 7 missions, which produces the deactivation_dates in the agents table that I want to update...
    SELECT
    s.deactivation_date
    FROM
    (
    SELECT
    a.deactivation_date,
    count(m.mission_id) as nomissions
    FROM
    agents a
    INNER JOIN
    missions_agents m
    on
    a.agent_id=m.agent_id
    GROUP BY
    a.deactivation_date
    ) s
    WHERE
    s.nomissions>7 AND s.deactivation_date IS NOT NULL
    .. .and the code for the first date of deactivation for each year of activation agent
    select 
    a2.deactivation_date
    from
    agents a2
    where a2.deactivation_date= 
    (
    select min(a.deactivation_date)
    from 
    agents a
    where to_number(to_char(a.activation_date,'YYYY'))=to_number(to_char(a2.activation_date,'YYYY'))
    )
    ..... I am not real to marry these two statements together in the Update statement. I can't extract each date of deactivation produced in the first select statement and their match against the first date of deactivation in the year they have been activated for the second select statement.

    Any help greatly appreciated... :))

    I began to wonder how things would :)

    user8695469 wrote:
    First of all why he chooses the date the earliest of all agents

    UPDATE  AGENTS_COPY AC /* (1) */
    SET     DEACTIVATION_DATE = (
    SELECT  MIN(AGS.DEACTIVATION_DATE)
    FROM    AGENTS_COPY  AGS
    ,       AGENTS_COPY AC /* (2) */
    WHERE   TRUNC(AGS.ACTIVATION_DATE,'YEAR') = TRUNC(AC.ACTIVATION_DATE,'YEAR') /* (3) */
    )
    

    He recovers as soon as the subquery has not been correctly set in the SET clause. It seems you are trying to update a correlated, but we are still having a conceptual shift. I have added a few comments to your code above and below will explain.

    (1): when you do a correlated update it is useful to the table alias that you did right here.

    (2): this table statement is not necessary and is the reason why the FIRST deactivation date is selected. The alias that you use (3) refers to THIS table, not the one defined in the update statement. Remove the line indicated by (2) in the FROM clause and a correlated update will happen.

    and secondly why is it to update each row, when I thought that I'm just the lines where the agents are disabled and missions > 7? Pointers on where I'm wrong would be very appreciated. (SQL = stupid query language!) :)

    user8695469 wrote: then why is it to update each row, when I thought that I'm just the lines where the agents are disabled and missions > 7? Pointers on where I'm wrong would be very appreciated. (SQL = stupid query language!) :)

    
    WHERE EXISTS
    (
    SELECT
    a.agent_id,
    count(m.mission_id)
    FROM
    agents a
    /* INNER JOIN AC ON AC.AGENT_ID = A.AGENT_ID */
    INNER JOIN
    missions_agents m
    ON
    a.agent_id=m.agent_id
    GROUP BY
    a.agent_id,
    a.deactivation_date
    HAVING
    count(m.mission_id)>7 AND a.deactivation_date IS NOT NULL
    )
    

    Once again this problem is similar to the question above that a correlation update doesn't work. Test existence of lines in an EXISTS subquery. Since your subquery is not related to the table that you are trying to update, it will be always return a line and, therefore, it returns true for EACH LINE in the AGENTS table. To limit the game to only agents > 7 missions results, you need to add a join condition that references the table in your update statement. I added one above (with comments) as a sample.

    I recommend you look over all material that you have associated with correlated subqueries, including documents that I posted above. This seems to be what you're having the problem more with. If you need me to explain the concept of correlated queries any better please let me know.

    Thank you!

  • Need help with the ANSI Join syntax

    Version: 11.1.0.7

    I have my select statement that returns 3000 lines and looks like
    select ..
    from tab1 a,tab2 b,tab3 c
    where a.c1=b.c1 and
    b.c2 = c.c2(+)
    and ...
    group by
    ..
    I want to convert it to ANSI SQL, because it must be able to Hibernate, and the developer says that Hibernate include only ANSI SQL. I tried something like
    select ..
    from tab1 a INNER JOIN tab2 b
    ON a.c1=b.c1 
    LEFT OUTER JOIN tab3 c
    ON b.c2=c.c2
    where ...
    group by
    ..
    I felt bad and it turned out to be the same. It returns no rows. Please help with the correct syntax.

    I'm not sure, sorry, because it's certainly the ANSI equivalent to the non-ANSI.

    Would you have examples of queries and data that you can reproduce the problem with, and that we could analyze?

    Published by: Seanmacgc on July 15, 2009 12:48

    If there is no Clause WHERE conditions in the original that are included in the ANSI version of the query in the WHERE Clause for the EXTERNAL table itself joined, then that could transform the JOIN JOIN internally, that is, all the filters on the EXTERNAL joined table should be included in the JOIN predicate - IT (b.c2 = c.2 AND c.c3 = 'X').

Maybe you are looking for