How to get the particular record last
HelloI want the query because if a particular record available when enter as a last record.
Ex,
name
----------
s
t
h
but t is always the last record. How to get?
Thank you
Alphadi.
Welcome to the forum.
Do you mean you want to 'h' to appear as the last record?
Try:
SQL> -- generating sample data:
SQL> with t as (
2 select 'h' name from dual union
3 select 's' from dual union
4 select 't' from dual
5 )
6 --
7 -- actual query:
8 --
9 select name
10 from t
11 order by case
12 when name = 'h' then 2
13 else 1
14 end;
NAME
--------------------
s
t
h
3 rows selected.
Tags: Database
Similar Questions
-
How to get the first and last record
Hai All
I have a table called T1 and there are more than 8 lakhs Archives and I have a column named Timestamp, so I need to get the first record value and time stampvalue and last record and time stamp value so that I can conclude that for example
form June 13 to 15 June data are here
Kind regards
SrikkanthMWhat is the problem with:
select min(timestamp),max(timestamp) from T1;
?
-
How to get the different records for the date max.
Hi all
Here is the sample sql for sample table and data.
Create table student (dept_id number(10), first_name varchar2(10),last_name varchar2(10),join_date date,years_attended number(10));
insert into student values (1,'Ann','Coleman',to_date('3/7/1917','MM/DD/YYYY'),4);
insert into student values (1,'Ann','Coleman',to_date('3/7/1916','MM/DD/YYYY'),5);
insert into student values (2,'Rock','Star',to_date('1/1/1920','MM/DD/YYYY'),5);
insert into student values (2,'Rock','Star',to_date('1/1/1921','MM/DD/YYYY'),6);
insert into student values (3,'Jack','Smith',to_date('7/1/1900','MM/DD/YYYY'),3);insert into student values (3,'Jack','Smith',to_date('7/1/1901','MM/DD/YYYY'),4);
commit;
I need to get maximum date records when the name and dep_id corresponds to. I wrote the query below and it becomes the expected result, but I'm not sure it's quite effective.
SELECT s.dept_id, s.first_name,s.years_attended
FROM (SELECT dept, MAX (join_date) join_date
STUDENT GROUP BY dept_id) x
Student JOIN s ON x.dept_id = s.dept_id AND x.join_date = s.join_date;
This above query returns records like below, and this is the goal.
DEPT_ID NAME YEARS_ATTENDED
1 Ann 4
2 Rock 6
3 Jack 4
Can you please let me know the query SQL I wrote is effective or not? This sample table may have less data, but I'm dealing with millions of records.
Hello
Thanks for posting CREATE TABLE and INSERT statement. This really helps.
Here's a solution. I also added a name that seems logical. In which case you can delete:
Select dept_id, first_name, last_name
, max (years_attended) Dungeon years_attended (last dense_rank order by join_date)
the student
Group of dept_id, first_name, last_name;
DEPT_ID FIRST_NAME LAST_NAME YEARS_ATTENDED
---------- ---------- ---------- --------------
1 Ann Coleman 4
Rock 2 star 6
3 Jack Smith 4
Kind regards.
Alberto
-
How to get the current record in a block?
Hello
How can I get the registration of a block, but the current record of the records displayed by this block? (for example if the number of records is 50, but the number of displayed records is 10, I want to get the current_record from the 10, not all 50).
the: system.current_record returns the current all-time record
Thank youYou can use a combination of: SYSTEM. CURSOR_RECORD which returns the current record and GET_BLOCK_PROPERTY ('BLOCK', TOP_RECORD), which returns the number of the record that is displayed as the first visible record, your result should be something like
:SYSTEM.CURSOR_RECORD-GET_BLOCK_PROPERTY('BLOCK', TOP_RECORD)+1;
-
How to get the previous record that meets a criterion?
Hello!
I am trying to create a query that adds information which finally fixed an element for a given 'pause'.
I have a table, let's call it actionHistory, which looks like:
ID | timestamp | action | author
------------------------------------------------
101477 | 2010-05-10 09:10:20 | Difficulty | Tim
101477 | 2010-05-10 09:10:30 | change | John
101477 | 2010-05-10 09:10:40 | breaking | Maggie
101477 | 2010-05-10 09:10:50 | Difficulty | Rick
222222 | 2010-05-10 09:10:30 | change | Lewis
222222 | 2010-05-11 09:10:40 | breaking | Maggie
222222 | 2010-05-11 09:10:50 | Difficulty | Tim
222222 | 2010-05-12 09:10:40 | Difficulty | Maggie
222222 | 2010-05-13 09:10:40 | breaking | Albert
I'm looking for is the following result:
ID | timestamp | action | author | lastFixBy
-----------------------------------------------------------
101477 | 2010-05-10 09:10:20 | Difficulty | Tim |
101477 | 2010-05-10 09:10:30 | change | John |
101477 | 2010-05-10 09:10:40 | breaking | Maggie | Tim
101477 | 2010-05-10 09:10:50 | Difficulty | Rick |
222222 | 2010-05-10 09:10:30 | change | Lewis |
222222 | 2010-05-11 09:10:40 | breaking | Maggie |
222222 | 2010-05-11 09:10:50 | Difficulty | Tim |
222222 | 2010-05-12 09:10:40 | Difficulty | Maggie |
222222 | 2010-05-13 09:10:40 | breaking | Albert | Maggie
Can you tell me how I can make?
I tried many ways but no return to what I'm looking for.
Thanks in advance.
Published by: user8910765 on June 5, 2010 13:51
Published by: user8910765 on June 5, 2010 14:00Hello
That's what you asked for in Oracle 10:
SELECT a.* , CASE WHEN action = 'break' THEN LAST_VALUE ( CASE WHEN action = 'fix' THEN author END IGNORE NULLS ) OVER ( PARTITION BY id ORDER BY tmstmp ) END AS lastfixby FROM actionhistory a ORDER BY id , tmstmp ;
Like all of the built-in functions, LAST_VALUE is documented in the manual of the SQL language:
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions073.htm#sthref1508user8910765 wrote:
... just in case where it might be useful, one of the queries I've tried myself a left subquery joined that Oracle has no right ("a column may be outside not attached to a subquery').Much more, it would help if you posted the request.
It looks like you were using the old outer join notation (+). You can get the desired results by using an outer join with ANSI rating, but I think it would be more complicated and slower than with a LAST_VALUE. -
Get the firstday and last month lastday
Hello
How to get the first and last day of the last month?
I've used this, but it returns January 1, 2010
FirstDay:
Select TRUNC (SYSDATE, 'year') of double
LASTDAY:
Select LAST_DAY (ADD_MONTHS (SYSDATE-1)) of the doubleYou're close
SQL> select TRUNC(ADD_MONTHS (SYSDATE, -1),'month') fom, 2 LAST_DAY(ADD_MONTHS (SYSDATE,-1)) eom 3 from dual; FOM EOM --------- --------- 01-DEC-09 31-DEC-09
John
-
Hello my friends.
I am looking for information on how to get the date of the access and the user name who did use some WFs in OM and last WMS.
If it is through the application or running in the background via SQL for the information is not important to me.
Could you help me with this?.
Thank you
the 'item_type' attribute must match the name of the WF?
Yes (internal name. For example OEOL).
The custom of those who will not be affected by the upgrade.
You must run the query that I provided before to identify if the workflow is used or not.
For the workflow of order lines, it is intended to be used as you use the order management.
Kind regards
Bashar
-
How to get the last date of 3 days for the current month?
Hello. Guy
How to get the last date of 3 days for the current month?
MY OUTPUT WOULD LOOK LIKE THIS
JANUARY 29, 2016
JANUARY 30, 2016
JANUARY 31, 2016
GUYS HELP ME / / /...
SQL > select last_day (sysdate) - level + 1 double connect by level<= 3="" order="" by="">=>
LAST_DAY)
---------
29 JANUARY 16
30 JANUARY 16
31 JANUARY 16
-
How to get the last day of a month for every 2 months for a given period?
Hello
Can is it some please let me know how to get the last day, last day of the week, the weekend last day, last Monday, one month for every 2 months for a given period?
Thanks in advance.
Try the below
SELECT LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))) lastday.
BOX WHEN TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') = 'SAT '.
SO LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))-1
WHERE TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') = 'Sun '.
THEN LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))-2
Of OTHER LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))
END as lastweekday,
BOX WHEN TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') IN ('Sam', 'SUN')
THEN LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))
Of OTHER LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))
-(TO_NUMBER (TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))),' from)) - 1).
END as lastweekendday,
BOX WHEN TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') = 'MY
THEN LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))
Of OTHER NEXT_DAY (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), "LUN")-7
END AS lastmonday
FROM (SELECT SYSDATE startdate,
SYSDATE + 300 enddate
THE DOUBLE)
CONNECT BY LEVEL<=>=>
-
How to get the value of a particular column column name?
Hi all
How to get the column name for a particular column value.
example:
create table test (ID number, col2, col3 varchar varchar);
Insert into test values (1, 'true', 'false');
Insert into test values (2, 'false', 'true');
commit;
I want to choose the name of the data column 'true' with id = 1;
That is to say) while waiting for answer is "col2". pls help someone.This might help:
DECLARE c1 SYS_REFCURSOR; BEGIN OPEN c1 FOR SELECT col2, col3 FROM test WHERE id = 1; -- FOR c IN (SELECT rownum rn, t2.column_value.getrootelement() name, EXTRACTVALUE(t2.column_value, 'node()') value FROM TABLE(XMLSEQUENCE(c1)) t, TABLE(XMLSEQUENCE(EXTRACT(column_value, '/ROW/node()'))) t2) LOOP IF c.value = 'true' THEN DBMS_OUTPUT.PUT_LINE(c.name); END IF; END LOOP; END;
-
How to get the last day of the week?
HII
I can get the week number of calendar for a given date using
SELECT to_char (to_date('04/04/2011','MM/DD/YYYY'), 'WW') FROM dual
can any body tell me, how to get the last day of the week?
and the answer should be: 04/08/2011(8th april)
Thank you
San
Published by: sandeep9 on April 4, 2011 03:50Perhaps this...
SQL> select trunc(sysdate,'WW')+6 from dual; TRUNC(SYSDATE,'WW')+ -------------------- 08-APR-2011 00:00:00 SQL>
-
How to get the name of the particular index table option.
Hello
Can any body tell how to get the name of the item to a particular array.i have a table within array.i must compare the name of Francesca in particular key.here is the table.
myArray= Array (@43b1e09)
[0] = object (@42b33f9)
Testing_1 = Array (@4428821)
[0] = object (@43adc19)
choice_id = '0 '.
delete = "N".
DownloadURL = "xyz".
selected = 'Y '.
translation = "2_486."
length = 1
length = "N".
Editable = 'Y '.
field_id = '388 '.
LanguageLink = 'Y '.
linked_definition_id = null
multiple values = "N".
name = "Photo".
otheroption = "N".
photovitlink = object (@43ad0d9)
required = "N".
step = '1 '.
translation = "Photo".
visible = 'Y '.
[1] = object (@43ad5d9)
[2] = object (@4490089)Here is the structure of the table I get server side.i give table name of result as table myArray.This have several child as an object of object.each having .i table (Testing_1 in the first case) must get the name of this Testing_1 table and compare with my sort key that I perform an operation. But I am unable to get the name of this Testing_1 array(Since_it_is_dynamic_so_this_name_changes_some_times).can a body guide me how to get the name of this table.
Thanks and greetings
Vineet Sharma
Hi Vineet Osho,
You can browse your object using the loop and you can get the name of the table... as below...
for each (var obj:Object in myArray)
{
for (var str:String in obj)
{
If (obj [str] is array)
{
var arrayName:String = str;
}
}
}Thank you
Jean Claude
-
How to get the values separated by commas of multiple records in table
How to get the values separated by commas of multiple records in table
for example
name address age sex
a 12 m e
b hh 12 f
BB c 13 h
I need to get output as a, b, c from a queryUse the query as below he works for me, change the names of tables and columns
SELECT SUBSTR (SYS_CONNECT_BY_PATH (PROXY_EMAIL, ','), 2) csv FROM (SELECT PROXY_EMAIL, ROW_NUMBER () ON the rn (ORDER OF PROXY_EMAIL), COUNT (*) NTC (STARS_PROXY_ASSIGNMENT) WHERE EMPLID = #EMPLID) WHERE rn = cnt START WITH rn = 1 CONNECT BY rn = rn + 1 ADVANCE
-
How to get the value of a particular tag to a column (clob)
Hi friends,
How to get the value of a particular tag to a column (clob), which has an XML value?
Thanks in advance.
Kind regards
Sirot ChauvetYou are welcome, if you got your answer to the question as such brand
-
How to get the time of the device
Hello
I'm developing an application in which I send location of the device in lat, long for every 10 minutes. I want to send some time also with lat, long. This time must be peripheral situation updates for every 10 minutes. Can someone tell me how do I do this?
It is not obvious to your OP exactly what you ask.
Ask you in a certain way a consistent recording time no matter what time zone are you in?
Or are you just asking how to get the date and time?
If it's the last QDateTime is one of the ways to get the date and time...
http://developer.BlackBerry.com/native/reference/Cascades/QDateTime.html
If you ask for the first answer more complex, you will probably need to check the time against an external clock (say GMT) and then re-reading use the contact information you have saved to determine what the weather was (including a calculation of DST) at this point in this particular time zone.
Relying on the phone to change accurately that it is time that you move in time zones will not give accurate results.
Maybe you are looking for
-
DeisgnJet HP 750 c more: try to find the driver for HP DesignJet 750 c Plus - I have no disc
I recently inherited a HP DesignJet 750 c more. Its still in great condition and I think that works. I bought a new cable for it this week and foolishly taken I'd be able to download a driver for it on the HP website. Due to the age of the machine
-
HP 15-r100nia note: cannot install Updats after download
PLEASE FRIENDS, I CHECKED FOR UPDATE WITH MY LAPTOP BUT AFTER DOUNLOADING, WHEN INSTALLING MY SYSTEM WAS NOT ABLE TO INSTALL UPDATES, HIS WATCH HAS FAILED.
-
A "Not available in the country" app - game Google store
Hello users of Sony, I bought my Z2 Dubai and used for almost 6 to 9 months. Recently, I came back to my home country India and when I tried to install some applications (for the environmental goods and services:-Quikr, OLX India etc.), his watch tha
-
Rescue R710 &; RAID controller
Hi all I have an old R710 server and I need to do an upgrade of the RAID controller your suggestion for the best price/performance raid controller, please, I have a 4 TB drive Better compliance GVO
-
How can I add the date of my taskbar notification area?
I have the time but not the date in my notification area of the taskbar, how can I add the date?