Query to find first and last call made by selected number for date range
Hi,
query to find first and last call made by selected number for date range
according to filter:
mobile_no : 989.....
call_date_from : 25-april-2013
call_date_to : 26-april-2013
Please help
Hi,
It sounds like you want a Top-N Query , something like this:
WITH got_nums AS
SELECT table_x.* -- or list columns wanted
, ROW_NUMBER () OVER (ORDER BY call_date ) AS a_num
, ROW_NUMBER () OVER (ORDER BY call_date DESC) AS d_num
FROM table_x
WHERE mobile_no = 989
AND call_date >= DATE '2013-04-25'
AND call_date < DATE '2013-04-26' + 1
SELECT * -- or list all columns except a_num and d_num
FROM got_nums
WHERE 1 IN (a_num, d_num)
;This forum is devoted to the SQL*Plus and iSQL*Plus front ends. This question doesn't have anything to do with any front end, does it? In the future, you'll get better response if you post questions like this in the PL/SQL.
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.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the SQL forum FAQ {message:id=9360002}
Similar Messages
-
Finding first and last members of a group set
Is there any example how to use 'first' and 'last' functions in an sql query ?
I have tried to execute a query like this on the scott.emp table :
select deptno,min(sal),max(sal),first(sal) from emp group by deptno;
but I always get this message:
ERROR at line 1:
ORA-00904: "FIRST": invalid identifier
btw I use Oracle RDBMS ver 9.1.0.3 for Solaris in my server.
tx for your help
sjarifSyarif,
The FIRST and LAST functions, which became available with 9i, are used to find the first or last member of a ranked set. I'm not sure exactly what you are trying to do, but I can show you a query that should work (I don't have 9i handy at the moment). This query should give you the departments with the highest (first) and lowest (last) aggregate salaries:
select deptno,
min(deptno)
keep (dense_rank first order by sum(sal) desc) highest_sal,
min(deptno)
keep (dense_rank last order by sum(sal) desc) lowest_sal
from emp
group by deptno
Is there any example how to use 'first' and 'last' functions in an sql query ?
I have tried to execute a query like this on the scott.emp table :
select deptno,min(sal),max(sal),first(sal) from emp group by deptno;
but I always get this message:
ERROR at line 1:
ORA-00904: "FIRST": invalid identifier
btw I use Oracle RDBMS ver 9.1.0.3 for Solaris in my server.
tx for your help
sjarif -
How to find first and last date of a fiscal week using SQL
Hello,
I want information about FISCAL Week, means a Week based on ISO standard. I know format strings ‘IW’ or ‘IYYY’ gives fiscal week and fiscal year respectively from a given date. But I want to find the first and last date of a fiscal week. Say suppose I have a fiscal week is 2, and fiscal year is 2008, how to find the start and end date of the given fiscal week.
Any kind of help would be greatly appreciable.
Thanks,
Princedavide gislon wrote:
The following query evaluate the begin of a fisical week, where &year and &week are respectively the year and week you want to calculate.
To evaluate the end of the week you have to add 6.
Note that my database is set to have monday as day number 1 of the week, and sunday as day number 7; if your database settings are different you should modify the query accordingly.
SELECT CASE TO_CHAR(TO_DATE('&year','YYYY'),'D')
WHEN '1' THEN TO_DATE('&year','YYYY')+((&week-1)*7)
WHEN '2' THEN TO_DATE('&year','YYYY')+((&week-1)*7-1)
WHEN '3' THEN TO_DATE('&year','YYYY')+((&week-1)*7-2)
WHEN '4' THEN TO_DATE('&year','YYYY')+((&week-1)*7-3)
WHEN '5' THEN TO_DATE('&year','YYYY')+((&week-1)*7+3)
WHEN '6' THEN TO_DATE('&year','YYYY')+((&week-1)*7+2)
WHEN '7' THEN TO_DATE('&year','YYYY')+((&week-1)*7+1)
END BEGIN_FISICAL_WEEK
FROM DUAL
Hope this is helpful.
Cheers,
Davide
Edited by: davide gislon on 08-Jan-2009 07:19Your query does nothing you say it does. TO_DATE('&year','YYYY') returns first day of the current month for year &year. And the only reason it returns January 1, &year is that we are currently in January:
SQL> select TO_DATE('&year','YYYY') from dual
2 /
Enter value for year: 2005
old 1: select TO_DATE('&year','YYYY') from dual
new 1: select TO_DATE('2005','YYYY') from dual
TO_DATE('
01-JAN-05
SQL> As soon as we roll into February:
SQL> alter system set fixed_date = '2009-2-1' scope=memory
2 /
System altered.
SQL> select sysdate from dual
2 /
SYSDATE
01-FEB-09
SQL> select TO_DATE('&year','YYYY') from dual
2 /
Enter value for year: 2005
old 1: select TO_DATE('&year','YYYY') from dual
new 1: select TO_DATE('2005','YYYY') from dual
TO_DATE('
01-FEB-05
SQL> alter system set fixed_date = NONE scope=both
2 /
System altered.
SQL> select sysdate from dual
2 /
SYSDATE
08-JAN-09
SQL> But even if TO_DATE('&year','YYYY') would always return January 1, &year, or you would fix it to TO_DATE('0101&year','MMDDYYYY') it still would be wrong. ISO week rules are
If January 1 falls on a Friday, Saturday, or Sunday, then the week including January 1 is the last week of the previous year, because most of the days in the week belong to the previous year.
If January 1 falls on a Monday, Tuesday, Wednesday, or Thursday, then the week is the first week of the new year, because most of the days in the week belong to the new year.Therefore, next year:
SQL> DEFINE YEAR=2010
SQL> DEFINE WEEK=1
SQL> ALTER SESSION SET NLS_TERRITORY=GERMANY -- enforce Monday as first day of the week
2 /
Session altered.
SQL> SET VERIFY OFF
SQL> SELECT CASE TO_CHAR(TO_DATE('0101&&year','MMDDYYYY'),'D')
2 WHEN '1' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7)
3 WHEN '2' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7-1)
4 WHEN '3' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7-2)
5 WHEN '4' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7-3)
6 WHEN '5' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7+3)
7 WHEN '6' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7+2)
8 WHEN '7' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7+1)
9 END BEGIN_FISICAL_WEEK
10 FROM DUAL
11 /
BEGIN_FI
04.01.10
SQL> SELECT TRUNC(TO_DATE('0101&&year','MMDDYYYY'),'IW') FROM DUAL
2 /
TRUNC(TO
28.12.09
SQL> 2 user10772980:
Use:
SELECT TRUNC(TO_DATE('0101&&year','MMDDYYYY'),'IW') + (&&week-1)*7 FISCAL_YEAR_&&YEAR._WEEK_&&WEEK
FROM DUAL
FISCAL_YEAR_2010_WEEK_1
28.12.09
SQL> SY. -
How to find first and last day of last month?.
Hello,
I am using Crystal Report XI.
Reports will be generated on first of every month for
previous month. I want to find start and end date of previous month
dynamic.
For august, Start date is July 1st and End date July 31st.
For September, start date is Aug 1st and Aug 31st.
How can i get first of previous month as start date and last
day of the previous month as end date?.
Same kind of thing I want to do for future report ..find next
month start date and end date.
ThanksAdomacro,
you could do a function, like this
<cffunction name="getReportdates" returntype="struct"
hint="Given an arbitrary month and year, the function returns a
structure containing the first and last day of the previous
month">
<!--- Take current month and current year as the default
--->
<cfargument name="mnth" type="string" required="No"
default="#monthAsString(month(now()))#">
<cfargument name="yr" type="numeric" required="No"
default="#year(now())#">
<cfset firstDayOfGivenMonth = parseDateTime("1 " &
arguments.mnth & " #arguments.yr#")>
<cfset lastDayOfPreviousMonth =
dateAdd("d",-1,firstDayOfGivenMonth)>
<cfset numberOfDaysOfPreviousMonth =
daysInMonth(lastDayOfPreviousMonth)>
<cfset firstDayOfPreviousMonth =
dateAdd("d",-#numberOfDaysOfPreviousMonth#,firstDayOfGivenMonth)>
<cfset reportDates = structNew()>
<cfset reportDates.firstDayOfPreviousMonth =
firstDayOfPreviousMonth>
<cfset reportDates.lastDayOfPreviousMonth =
lastDayOfPreviousMonth>
<cfreturn reportDates>
</cffunction>
<!--- Example usage --->
<p>
Given month: <strong>March
2004</strong><br>
begin date:
<cfoutput>#dateFormat(getReportdates('March',2004).firstDayOfPreviousMonth,"d
mmm yyyy")#</cfoutput><br>
end date:
<cfoutput>#dateFormat(getReportdates('March',2004).lastDayOfPreviousMonth,"d
mmm yyyy")#</cfoutput><br>
</p>
<p>
Given month: <strong>August
2007</strong><br>
begin date:
<cfoutput>#dateFormat(getReportdates('August',2007).firstDayOfPreviousMonth,"d
mmm yyyy")#</cfoutput><br>
end date:
<cfoutput>#dateFormat(getReportdates('August',2007).lastDayOfPreviousMonth,"d
mmm yyyy")#</cfoutput><br>
</p> -
How to find first and last day of previous month?.
Based on current month, I want to find start and end day of
previous month.
For example,
For august, Start date is July 1st and End date July 31st.
How can i get first of previous month as start date and last
day of the previous month as end date?.
Same way,
i want to find start date of current month and end date of
next month.
Example:
For august,
i want to get start date, august 1st and end date : september
30.
How can i do this from current date or now().
I am looking for best and easy way to find start and end
dates..
Thanks<cfset today = now()>
<cfset firstOfThisMonth = createDate(year(today),
month(today), 1)>
<cfset lastOfNextMonth = dateAdd("d", -1, dateAdd("m", 2,
firstOfThisMonth))>
<cfoutput>
today = #today#<br>
firstOfThisMonth = #firstOfThisMonth#<br>
lastOfNextMonth = #lastOfNextMonth#<br>
</cfoutput>
Edit - To find the start and end day of previous month, get
the first of THIS month. Use Subtract 1 month ("m") to get the
start date. Subtract 1 day ("d") to get the end date. -
Find the first and last day of week giving a certain date
Hi,
i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?
Many thanks in advance,
Nuno Almeidanfalmeida wrote:
i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?First step is being sure that you know what a 'week' is.
For example does it really start on monday? And will it always start on monday?
And what day does the 'week' end on for 2010-12-29? In some businesses it will end on 2010-12-31 (friday) -
Sql query to find answered and received calls for month or day
Hi experts !
1.Any one help in finding out the received, answered and missed ,transfered in / out calls in UCCE using SQL query for a particular month or day.
2. We have some custom report templetes defined , need to know , how can we write Sql query to get those values from custum reports.
due to some issues, cannot use webview .Hi,
there's no such thing as reporting "for a particular Team". Teams in ICM are for administration purposes only (to have grouping of agents). ICM does not count the number of calls received by "teams". If there is a report in Webview "by team", it's always by agent. Try to run the report against a team once and then try to remove certain agents from that team - you'll see the difference.
What you are looking for is either reporting by Agent or by Agent/Skill group combination.
Try to explore the
- Agent_Half_Hour
- Agent_Skill_Group_Half_Hour
- Skill_Group_Half_Hour
database views.
The database schema documents are here:
http://www.cisco.com/en/US/products/sw/custcosw/ps1844/prod_technical_reference_list.html
Good luck.
G. -
TSQL Query to display First and Last Values of a GROUP as Columns - SQL Server 2008
Could someone please help with the TSQL to achieve the following: Every Employee has 2 records (From & To). Output has to display one record for each employee with From & To as columns.
Input
Empid
Type
Date
100
From
5/4/2004
100
To
6/2/2008
101
From
6/12/2003
101
To
6/2/2013
102
From
12/12/2012
102
To
5/3/2014
Output
EmpID
From
To
100
5/4/2004
6/2/2008
101
6/12/2003
6/2/2013
102
12/12/2012
5/3/2014
Thanks, Ashish SinghSELECT empid,
MAX(CASE WHEN Type='From' THEN date END) from,
MAX(CASE WHEN Type='To' THEN date END) to
FROM tbl GROUP BY empid
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
First and last day of current year as a date object
Howdy...
can someone please help me out... i need a fast way to get the first day of the current year as a date object and the last day of the current year as a date object...
big thanks for any sample code...import java.util.Calendar;
// snip
Calendar firstDayOfYear = Calendar.getInstance(); // will initialize it with today
firstDayOfYear.set(Calendar.DAY_OF_MONTH, 1);
firstDayOfYear.set(Calendar.MONTH, Calendar.JANUARY);
Calendar lastDayOfYear = Calendar.getInstance(); // will initialize it with today
lastDayOfYear.set(Calendar.DAY_OF_MONTH, 31);
lastDayOfYear.set(Calendar.MONTH, Calendar.DECEMBER);Rommie. -
Query : first and last 25 records of a table
Hi @ll,
i am going to write a query for a report. Therefor i need the first and last 25 records of a table. Does anyone got an idea for a solution ? I was trying to achieve this by using a WHERE clause. Here is a part of the query :
SELECT
TOP 10 T1.[ItemCode], DATEPART(mm, T1.[DocDate]) [.....]
FROM FROM INV1 T1
Where T1.[DocDate] >= Cast('2009 [......] AND
T1.ItemCode = (
SELECT TOP 10 T40.[ItemCode]
FROM DBO.OINM
WHERE Where T40.[DocDate] >= Cast('2009-04-01 00:00:00' AS datetime)
AND T40.[DocDate] <= Cast('2009-04-30 00:00:00' AS datetime)
GROUP BY T1.[ItemCode], DATEPART(mm, T40.[DocDate])
ORDER BY SUM(T1.[TotalSumSy]) ASC)
The where part i would use twice, once for ascending the other one for descending. But it does not work.
Any ideas ?
Regards SteffenHi,
Union was the keyword, that i was searching for. It is a nice way, but not practible.
We are using coresuite for generating reports, and there were a nice possibility to connect diffrent queries.
Thanks for your suggestion.
Regards Steffen -
Format first and last record of result query
Hello
I have the following query
<tt>select 1 seq, 'This is First record' data from dual union all
select 2, 'Data ' || tname from tab union all
select 3, 'This was last record Last record' from dual
order by 1</tt>
When i spool this statement to a listfile with col seq noprint option i get:
This is First record
Data MLA_ACCESS_LIST
Data MLA_APPLICATIONS
Data MLA_VPD_PCK
Data MLA_VPD_TABLES
This was last record Last record
But i want:
This is First record MLA_ACCESS_LIST
Data MLA_APPLICATIONS
Data MLA_VPD_PCK
MLA_VPD_TABLES This was last record Last record
I tried it with 1 statement with usage of lead and lag, because first and last record have to differ from the other result records. But i get ORA-30484: missing window specification for this function
Is this possible with 1 statement or am i doomed to edit the results by myself?
Thanks Aukeselect case row_number() over (order by tname)
when 1 then 'This is the First record '
end || tname ||
case row_number() over (order by tname desc)
when 1 then ' This was the last record'
end
from tab
order by tname
hth -
Jbo:DataScroller - how to ensure 'First' and 'Last' action links appear
I'm working in JDeveloper 10.1.3.5.0.
I'd like to know if there's a way to ensure that the action links 'First' and 'Last' will appear, in addition to the 'Next' and 'Previous' ones (that is, assuming we're not already at the first or last range position).
It seems as if the thing that determines whether or not they appear is the number of total range positions. I can't be certain, but it seems like the magic number is 1000. If there are fewer, then 'First' and 'Last' will appear, and if there are more, then they will not. It'd be great to be able to have control of this, though. Is it possible?
Thanks
SheaEncore is being phased out? I would be surprised if Adobe did not offer some kind of DVD authoring solution in it's place. I have not heard about this yet myself.
I have a menu size issue because, despite my reported file size being under 4.7G, Encore continues to report a menu size problem. Of course it doesn't say which menu or by how much it is exceeded. When I build it to DVD it waits several hours before reporting that there is a space issue. See below.
There is a file called woodstock-1.mp4. I can find no use of this clip at this point and it's not part of a timeline, yet Encore won't let it be deleted. Encore reports it's still in use. Surely there should be some way to track down any dependencies quickly. -
FM for First and Last Day_Current Month
Hello All,
Inorder to update the TVARV table, two new variables were needed which will get the First and Last Day of current month.
One FM i was able to find was BKK_GET_MONTH_LASTDAY which takes the Todays date and outputs the Last date of the month. IS there any FM for FIRSTDAY Current month....
Regs,
-PSKHi Sravan,
Following help may help you.
FM - BUILD_PERIOD_TABLE
code is mentioned below.
data: it_cperiod type table of range_prds with header line,
define one variable as range like -
ranges: r_cperiod for sy-datum,
CALL FUNCTION 'BUILD_PERIOD_TABLE'
EXPORTING
YEAR = <current year>
TABLES
PERIOD_TABLE = it_cperiod.
read table it_cperiod with key per_id = <current month>
refresh r_cperiod.
r_cperiod-sign = 'I'.
r_cperiod-option = 'BT'.
r_cperiod-low = it_cperiod-begda.
r_cperiod-high = it_cperiod-endda.
append r_cperiod.
Now, you can see begin and end of moth in r_cperiod.
Regards,
Parag -
Hi,
I am trying to create a document that is similar to a dictionary or an index of information.
I want the first and last word on each page to be displayed automatically at the top corner and bottom corner of each page, to make navigation in the document easier.
Is there a way to do this in InDesign?
(If it is not done automatically, then if there is any shift in the lines, everything will be off, so i would Iike to find a way to do this.)
ThanksThat can be done with text variables (only in CS3 and later, though).
Read http://help.adobe.com/en_US/InDesign/6.0/WS6A9BE096-77B2-4721-9736-797C4912B6C9a.html, the section called "Create variables for running headers and footers". -
Get first and last date of month
Hi,
Is there any function module to get first and last date of month for a entered date.
Please let me know.
Regards,
SPHi,
Use the below FM to find the Last day of month and them u can easily calculate the first day.
DATA : v_startdate TYPE sy-datum.
DATA : v_enddate TYPE sy-datum.
DATA : v_temp TYPE dats.
v_temp = sy-datum.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = v_temp
IMPORTING
last_day_of_month = v_enddate
CONCATENATE v_enddate+0(6) '01' INTO v_startdate.
Hope it helps.
Regards,
Arnab.
Maybe you are looking for
-
How can I have My applet work with the browser ??
I created an applet but it giving an error when I try to put in a web browser package applet; //This Java Program determines the amount on maturity. import javax.swing.*; import java.awt.*; import java.awt.event.*; import static java.lang.Math.*; imp
-
Please help me to install Google Gmail update app for my First Generation iPad 3G.
-
Is it possible to connect 2 usb devices to an Airport Extreme?
Is it possible to connect 2 usb devices to an Airport Extreme (either the newest, ac model or the previous model) using a usb hub?
-
How can I set the flash cursors as my windows cursors?
I would like to set the cursors in Flash Pro CC to be my default windows cursors, since they are so nice. I've tried looking through the Flash Pro folder on my computer for .png, .gif, .jpg, .jpeg, .ani, and .cur files but none of those searches turn
-
.java files don't compile on redhat
im using redhat 9. i installed the binary of JDK in the bin folder when i type javac and then press enter, it says command not available or something like that actually i did it after when i could not compile .java files like: javac Hi.java moreover