getting the last area for each case
Hello all;I have a table with the following information below
create table tmp_a
(
idv number(30),
personid number(30),
Area varchar2(200),
dateadded date,
is_close number(2)
);
insert into tmp_a
(idv, personid, area, dateadded, is_close)
values
(1, 10001, 'ZONE_A', sysdate, 1);
insert into tmp_a
(idv, personid, area, dateadded, is_close)
values
(2, 10002, 'ZONE_B', sysdate, 0);
insert into tmp_a
(idv, personid, area, dateadded, is_close)
values
(3, 10003, 'ZONE_A', sysdate, 0);
insert into tmp_a
(idv, personid, area, dateadded, is_close)
values
(4, 10003, 'ZONE_A', sysdate, 0);
Now, I'd like to get this belowidv Personid Area Dateadded Is_clode
4 10003 Zone_A 3/3/2011 1:00:37PM 0
2 10002 Zone_B 3/3/2011 12:17;14PM 0
the output is based on the fact if there are duplicates associated with the area, the query should choose the last... In this case, the last being for zone_A is idv 4.Please note, idv is a primary key. How can I do this? Any help is appreciated. Thank you.
select max(idv) keep(dense_rank last order by dateadded,idv) idv,
max(personid) keep(dense_rank last order by dateadded,idv) personid,
area,
max(dateadded) dateadded,
max(is_close) keep(dense_rank last order by dateadded,idv) is_close
from tmp_a
group by area
order by area
/
IDV PERSONID AREA DATEADDED IS_CLOSE
---------- ---------- ------------------------------ ------------------- ----------
4 10003 ZONE_A 03/03/2011 13:12:50 1
2 10002 ZONE_B 03/03/2011 13:12:50 0
2 rows selected.
SQL>
SY.
Tags: Database
Similar Questions
-
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)
Explanation of the data in the sample table:*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
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:
Query 2:*DateCol1 Value Database* 27.09.2009 150 DB1 27.09.2009 1100 DB2 28.09.2009 220 DB1 28.09.2009 2000 DB2
The query should return the average measurement for each day and the database. Like this:
Could someone please help me to write these two queries?*DateCol1 Value Database* 27.09.2009 125 DB1 27.09.2009 1050 DB2 28.09.2009 210 DB1 28.09.2009 1750 DB2
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:17Why 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
-
get the maximum number for each group
Hi, I am a newbie and work on a project for school. I worked this problem for a few days and made a bit of progress.
I have two tables, student and register for a database of the College. I need to show students that have the most entries into each large. So far, I have:
WITH COUNT_Q AS
(
SELECT B.SSN, B.MAJOR, COUNT (A.CLASS_NO) AS COUNTCLASS
TO REGISTER A, STUDENT B
WHERE A.SSN = B.SSN
B.SSN GROUP, B.MAJOR
)
SELECT MAX (COUNTCLASS), MAJOR
OF COUNT_Q
GROUP BY MAJOR
;
I get the correct results, but need to introduce the SSN and the Major of the studens. When I add in the SSN and major, as below, I get too many files.
WITH COUNT_Q AS
(
SELECT B.NAME, B.SSN, B.MAJOR, COUNT (A.SSN) AS COUNTCLASS
TO REGISTER A, STUDENT B
WHERE A.SSN = B.SSN
B.NAME, B.SSN, B.MAJOR GROUP
)
SELECT *.
OF COUNT_Q
WHERE (COUNTCLASS) IN (SELECT MAX (COUNTCLASS)
OF COUNT_Q
GROUP BY MAJOR
)
;
Can someone point me in the right direction?SELECT B.NAME, B.SSN, B.MAJOR FROM ( SELECT B.NAME, B.SSN, B.MAJOR, COUNT(A.CLASS_NO) SSN_MAJOR_COUNTCLASS DENSE_RANK() OVER(PARTITION BY MAJOR ORDER BY COUNT(A.CLASS_NO) DESC) RNK FROM ENROLL A, STUDENT B WHERE A.SSN = B.SSN GROUP BY B.NAME, B.SSN, B.MAJOR ) WHERE RNK = 1 /
SY.
Published by: Solomon Yakobson, March 27, 2011 18:53
-
How to get the last records of a Table
Hey Geeks,
I have this 'conflict '.
I need to get the 'current balance' for each account, the newest "current_Balance".
The table looks like this
ACCOUNT_ID BUSINESS_TRANSACTION_ID CURRENT_BALANCE TRANSACTION_AMOUNT TRANSACTION_DATE 1 062 570 238 043 517 51'022 -20'000 31.03.2014 17:49:00.808000 1 062 570 238 042 407 71'022 -20'000 31.03.2014 17:33:55.666000 1 062 570 238 042 368 91'022 -26'000 31.03.2014 17:33:20.067000 1 062 570 238 041 273 117'022 -50,000 31.03.2014 17:18:25.189000 1 062 570 238 041 174 167'022 -10,000 31.03.2014 17:16:59.361000 1 062 570 238 038 702 177'022 -2'500 31.03.2014 16:44:58.332000 5 607 555 238 046 713 1'026 -28'500 31.03.2014 18:35:16.212000 5 607 555 238 040 592 29'526 -100,000 31.03.2014 17:10:15.474000 I need this result:
ACCOUNT_ID CURRENT_BALANCE
5 607 555 1'026
1 062 570 51'022
How we handle this?
Thxs for your help
Ineffective :-)
SELECT Account_id
MAX (current_balance) KEEP (DENSE_RANK LAST ORDER BY transaction_date) current_balance
MAX (business_transaction_id) KEEP (DENSE_RANK LAST ORDER BY transaction_date) business_transaction_id
Of account_balances
GROUP BY account_id
Concerning
Marcus
-
How to get the last row and the sum of all columns in a query
Hello
is there a way to get the last record for a column and the sum of all the Archives to another column in the same query.
Best regards
You must set your needs correctly volunteers to help here...
Your data are not good enough to bring you a precise solution. Purpose, you do not have a column, which draws a distinction between the first and the last entry.
The solution becomes easy based on your design.
I introduced a grouping called 'id' column and a time column called 'time_of_insert' (only this way you can say with confidence that you can differentiate between the first and last (also a foolproof solution) - you can possibly use sequence (instead of date but if you say that you can insert two lines at the same time) ((and then likely sequence would be a better choice to differentiate instead of a timestamp field) etc...)
With your sample data, something like this can be done to get the desired results.
-----------------------------------------------------------------------------------------------------------------------
WITH dataset AS
(SELECT 1 id, 10 used, 8 remain, systimestamp + 1/24 time_of_insert FROM DUAL
UNION ALL
SELECT the 1 id, 1, 7, systimestamp + 2/24 FROM DUAL
UNION ALL
SELECT the id 1, 2, 5, systimestamp + 3/24 FROM DUAL
UNION ALL
SELECT 1 id, 1, 0, systimestamp + 4/24 FROM DUAL
UNION ALL
SELECT 1 id, 0, 0, systimestamp + 5/24 FROM DUAL
UNION ALL
SELECT the 1 id, 1, 4, systimestamp + 6/24 FROM DUAL)
SELECT *.
(SELECT SUM (used) ON sum_all)
FIRST_VALUE (stay)
COURSES (PARTITION BY id ORDER BY time_of_insert DESC)
last_row
Of THE dataset)
WHERE ROWNUM = 1;
Output:
------------------------
SUM_ALL LAST_ROW
------------------------------
15 4
See you soon,.
Manik.
-
I have been using Photoshop CS5 for some time for photos products (jewelry). What are my best options to get the last Photoshop.
Hi michaelb.
You can subscribe to Plan photography for $9.99 a month, which will give the latest version of Photoshop CC 2015, CC 2015 Lightroom and Adobe Bridge.
Lightroom and Photoshop | Plan of cloud of Adobe's creative photography
Kind regards
Mohit
-
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
-
If I buy the photographer package, can I install on my macbook pro and my mac mini desktop. Where can I get this twice, one for each?
Cloud license allows 2 activations http://www.adobe.com/legal/licenses-terms.html
-Install on a 2nd computer http://forums.adobe.com/thread/1452292?tstart=0
-Windows or Mac has no importance... 2 on the same operating system or 1 on each
-Two activations on one account CAN NOT be used at the same time (to be noted in the link above of the license)
-An individual account is for one person and may not be shared with anyone else
-
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 last DML statement in each block
Hello
How can I get the latest DML statements in each block.
As SYSTEM. LAST_QUERY returns the last select statement, I need to get the last Insert/Update/Delete statement
in each block.
Thanks in advance
RizlyRizly,
You can use the GET_BLOCK_PROPERTY to get the last query executed on this block.
MESSAGE(GET_BLOCK_PROPERTY('
', LAST_QUERY)); Kind regards
Manu.
If this answer is useful or appropriate, please mark. Thank you.
-
Where can I get the right drivers for Satellite Z930 - PT23LA - 01 009?
A little history: I recently bought a version of Win7 to a Z930 in Auckland from PB Tech shop. I've updated to a clean version of Win8 64-bit. My Win8 seems works ok but I noticed something strange in the Toshiba PC Health Monitor - apparently the Toshiba HDD/SSD Alert is not installed, so I don't understand not his iconic display in the health monitor (but the health monitor think my SSD is in "Good" shape - maybe it's reading the INTELLIGENT of my SSD interface, or maybe it's just saying 'Good' because the integrity monitor is apparently able to operate?)
I can easily find different versions of the Toshiba HDD/SSD Alert Utility in questionable Web sites - download, but I really prefer to get my Toshiba support drivers. Which leads to my question:
Where can I get the right drivers for PT23LA-01 009? NZ nor the webarea to Toshiba support have this model in their menus. The closest match seems to be
http://www.MyToshiba.co.nz/support/computers/Ultrabook/satellite-z930/pt23la-01f00n/download?OS=30
There is probably not much difference between a PT23LA-01F and a PT23LA-01 P but it is a bit of concern to be download & install the drivers for a chip that is no my model...
See you soon,.
ClarkPS: http://forums.toshiba.com/t5/General-Features-Knowledge-Base/TOSHIBA-HDD-SSD-Alert/ta-p/347120 advise me the area downloads for Toshiba support. He also advises "not all utilities are available for each model and operating system. During the installation of utilities, install the TOSHIBA value added first. "Sigh... so maybe my problem is that I installed the Win8 drivers & utilities order when build my own-building a Win8 pass win7? Wouldn't surprise me in the slightest... but if this is the case are here all other dependencies in these built?
> Where can I get the right drivers for PT23LA-01 009?
First series of Toshiba laptops (Australian, European, etc) is very similar to the other
Your model of laptop Australian Satellite Z930 * PT23LA * series is the same as the European model Satellite Z930 * PT23LE * series.That's why the drivers, tools and utilities published for Satellite Z930 * PT23LE * series must be compatible with the Satellite Z930 * PT23LA * series.
To get all drivers for Satellite Z930 * PT23LE *, you should check this page:
http://www.Toshiba.EU/innovation/download_drivers_bios.jsp?service=EUThere, you can get all win 8 - upgrade the drivers. Also the HDD/SSD Alert Utility v3.1.64.14
Welcome them
-
The line of the last line of each table page is going to be missing.
Hi Experts,
In OBIEE 11.1.1.6.0, I have a report contains more than one line. "When I click on" PDF "Print", the last line of each table page line will be missing. " Why?
Are you facing the same case? How soluve this question? Thank you.Hey Kobe,
The question, looks lke a bug. Here's the work around, change the table view, click the properties of content next to the text "Table" (at the top of the columns and measures) in the layout-> position In Border pane to choose custom and select only the bottom edge (horizontal line). Now export to pdf format, you must see the border for the last row on each page.
Kind regards
DpKa -
I get a lot of my music from Soundcloud where individual songs are released by artists often with none of the albums.
So, when you add these songs on iTunes I the name of the album for each of them SoundCloud despite the fact that each of them have different names track/artists/works of art. When I select the option to indicate that the song is part of a compilation album, even if the individual work remains in each song and shows when I play the song, looking at my playlists, songs from my compilation album of SoundCloud will only show album art compilation rather than the individual works for each song. How can I my iTunes will show that each individual work?
You can't while retaining spacing as part of this same album. If you want each art individual to show then tracks them to a unique combination of the album title and album artist. If the tracks are underway on an older iPod then the tracks on the album must be unique.
TT2
-
How to get the last business day of the previous month?
Hi all
We need the user as below,
If the user select 18 June 2015 ' quick dashboard as the input value, and then they want to see last month last day of work (business date: 29-may-2015) amount in report, if you have an idea please share with us.thanks
Note:
use under request we can able to get the last day of the previous month, we want to for the last business day of the last month, based on the date of entry of the user?
TIMESTAMPADD (SQL_TSI_DAY,-(1), TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH ("DIM_TIME". ("" DataDate ") *-(1) + 1,"DIM_TIME ". (("" DataDate "))
Thank you
Deva
Try this,
case when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 1 then timestampadd (sql_tsi_day, (Dayofmonth(Date '2015-06-15') *-1)-2, Date '' 2015-06-15) when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 7 then timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1-1, Date '' 2015-06-15) another timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15') end
As Ftsiot said in this post, it will work only to exclude the sat and Sun. Another one if you want to exclude regional holiday, you may need a calendar in DB table.
Thank you
AJ
-
How can I get the stream position for a publication?
I am writing a CEAP for AfterFx plugin and I need to get the stream position for a composition. I based my plugin on ProjDumper.
Can anyone help?
When you place the compA in compB you are supposed to receive an AEGP_LayerH, for this comparison of layer nesting.
If not, you can use AEGP_GetCompLayerByIndex() on compB to obtain this handle layer, because you know its index. (you must know, you put here)
If you try to find the layer in compB starting only with the AEGP_CompH of the company, so it's a bit problematic...
You cannot just ask wherever model is nested, you must analyze each layer for this source control project... yuk.
Maybe you are looking for
-
Desabeling/disable the touchpad
I have a laptop HP 250 and I is not able to turn off or disable the touchpad. How can I activate the touchpad?
-
Multi-disc Albums in Windows Media Player
I mainly use the Zune software for music, but I use WMP for music between computers. I have a number of two record albums, that Zune allows me to specify that the two disks of the same album, which allows me to keep the numbers of tracks (1 to X on e
-
A month ago my 5550 from interference. When I studied, I found that the image transfer kit had been damaged. I have now replaced the roller and fuser (as well as toners as they were low). However, I still get the same error of the machine - 13.09.00
-
Before I used to be able to type in a series of characters, beginning with ALT and get a series of special characters, a bullet for foreigners. Now with Vista (on my mother ' puter) I can't get this to work. Can someone help me? I need to type in a d
-
How to stop Windows 10 download
Hello every time I try to install windows updates, it shows me to download windows 10 and I don't want that I have delited KB2952664 KB3021917 KB3035583 and always present, I delited $WINDOWS. ~ BT and GWX.exe and when I try to install the updates, i