Selecting Records for Today only?
I feel this should be an easy one, but everything I try is throwing back zero results.
Basically, I have an existing query that uses an outer join to bring 2 tables together (it's for some very basic site tracking).
Without the 'WHERE' clause, it performs exactly as I'd hoped. However, I need to be able to narrow down the results to the current day only (and perhaps other date ranges in the near future).
The final output I'm looking for is a list of sites, and the unique visitors for each. Again, this works fine when I run it without narrowing down to today only. The 'eventdt' field on the MySQL server is a datetime type.
<cfquery name="getsites" datasource="#datasource#">
SELECT s.id, s.sitename, count(DISTINCT t.uuid) as t_cnt, t.eventdt, t.sitename AS tracksite
FROM sites s
LEFT JOIN tracking t
ON s.sitename=t.sitename
WHERE t.eventdt = #CreateODBCDate(now())#
GROUP BY s.sitename
ORDER BY s.sitename ASC
</cfquery>
Thanks in advance for any pointers :-)
today = createdate(year(now()), month(now(), day(now()));
tomorrow = dateadd("d", 1, today);
in your query
where eventdt >= today
and eventdt < tomorrow.
With proper syntax of course.
Similar Messages
-
Hello folks,
Many times we need to retrieve records for given lists of PKs (or FKs), as:
p_pk_list := '11,22,33';
We work in 10g
A co-worker of mine had a good idea (I thought) to "help" the optimizer and build a recordset in the FROM clause and use it later in WHERE
SELECT ...
FROM tableName a,
(SELECT REGEXP_SUBSTR(p_pk_list, '[^,]+',1,ROWNUM) p_pk_id
FROM dual
CONNECT BY ROWNUM <= LENGTH(p_pk_list ) - LENGTH(REPLACE(p_pk_list ,','))) d_pk
WHERE
a.ID=d_pk.p_pk_id; -- (1)
The tragedy is that it takes 4 seconds to retrieve 5 records from the table (no other joins). The table has about 40 columns though and there are about 51000 records. With the SELECT REGEXP_SUBSTR in the WHERE clause, it's a bit worse.
If (1) is replaced by:
a.ID IN (11,22,33,44,55);
the execution takes 0.04 seconds.
My questions are:
1. Is this a bad idea to select records for a given list of PKs or FKs? Should one just go for one PK/FK instead?
2. Why the stiff performance penalty?
3. Ideally, it would be nice if this would work:
a.ID IN (p_array);
where p_array would be an array of integers
Any elegant sollutions?
Thanks a lot.
DanCheck the explain plan for both statements.
I would wager that the overhead you experience is due to the fact that you are comparing apples to oranges here.
(SELECT REGEXP_SUBSTR(p_pk_list, '[^,]+',1,ROWNUM) p_pk_id
FROM dual
CONNECT BY ROWNUM <= LENGTH(p_pk_list ) - LENGTH(REPLACE(p_pk_list ,','))) d_pkreturns a string.
a.ID IN (11,22,33,44,55);Is a list of numbers.
If you check the explain plan for the regexp version, you should see an implicit conversion being done for you (converting the number column into a string for comparison) which means you can't use any indexes defined on a.id.
If you want to use an array of numbers here's an approach using a built in array of numbers.
declare
v_number_list sys.odcinumberlist default sys.odcinumberlist();
begin
v_number_list.extend;
v_number_list(v_number_list.count) := 100;
v_number_list.extend;
v_number_list(v_number_list.count) := 200;
for vals in
select *
from all_objects
where object_id in
select column_value
from table(cast(v_number_list as sys.odcinumberlist))
loop
dbms_output.put_line(vals.object_name);
end loop;
end;
25 /
I_TYPED_VIEW1
I_NTAB2
PL/SQL procedure successfully completed.
ME_XE?Otherwise do an explicit TO_NUMBER on the regexp query so that you can use any indexes defined on the table in question. -
Select statement for today's date
Hi,
I need to write a select query which fetches all the entries of a table for today's date , how do i do it pls..Hi,
SELECT <field-names to retrieve>
FROM <database table name>
INTO TABLE <internal table name>
WHERE <date field name> eq sy-datum.
or
SELECT * FROM <database table name>
INTO TABLE <internal table name>
WHERE <date field name> eq sy-datum.
this statement will fetch all the data's from your database table with respect to your date field. use parameter or select option to get the field value...then finally use
loop at <itab>
write: / <itab-field>.
endloop. -
Data Selection option for Measures only?
Hi All I have Data Source with 3 dimenstion and few measures. I see that We can pick measures to dispaly,, but can i also pick dimenstion to show on horizonatal a-axis ? In screenshot below, I would like to pick one domension for chart A and pick 2nd dimension for chart B.
It's clear, but the selection you are showing above is only to bind measures.
Why not use a filter panel, dimension panel, etc. to filter? -
Select record from database table
how to select a record from data-base table for current month in module-pool, i.e if current month is august then records selected should between 1/08/10 to 31/08/10.
And, i also want to select records for last month i.e if current month is august then records selected should be between 1/07/10 to 31/07/10.
And one thing more, it should work for every scenario. Like for months are changing then it should work according to that.
Example: If month changes to October then current month ll be October and last month ll become September.
Plz help me out.
Moderator message: you chose a better forum this time, but the question is still too basic to be asked here, please (re)search yourself first, these forums are not catering to beginners.
locked by: Thomas Zloch on Aug 8, 2010 9:41 PMHi Nishant,
You can use the option <b>ORDER BY </b> in your SELECT clause.
This is the SAP Documentation for <b>ORDER BY </b> option.
<i>Variant 1</i>
<b>...ORDER BY PRIMARY KEY</b>
<b>Effect</b>
Sorts the selected lines in ascending order by the primary key of the database table. This variant is only permitted for SELECT * ....
<i>Notes</i>
Since views do not have a primary key, specifying ORDER BY PRIMARY KEY only makes sense with database tables. If, however, you do specify ORDER BY PRIMARY KEY with a view, all fields of the view are sorted in ascending order.
<i>Variant 2</i>
<b>ORDER BY f1 ... fn</b>
<i>Effect</i>
Sorts the selected records in ascending order by the specified column references f1 ... fn. If a list is also specified in the SELECT clause, the column references f1, ..., fn must appear in this list.
By supplementing the statement with DESCENDING, you can sort in descending order using any of the fields f1, ..., fn.
The default sort sequence is ascending order, but you can make this explicit by adding the addition ASCENDING.
Consider this code this will select the latest 10 records form DB table(Note can use <b>Variant 2</b> for DB tables also.
REPORT zarun_1.
DATA : it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE.
START-OF-SELECTION.
SELECT * FROM mara
INTO TABLE it_mara
<b>UP TO 10 ROWS "No of rows you need(give 1 here)
ORDER BY matnr DESCENDING. "Specify the Key Fields here.</b>
LOOP AT it_mara.
WRITE : / it_mara-matnr,
it_mara-mtart.
ENDLOOP.
Regards,
Arun Sambargi.
Message was edited by: Arun Sambargi -
"Key and Text" values in variable selection list for a field
Hi,
we have created the variable for the one of the navigation attributes of the "0customer" field .
for the customer field in BEX settings we are having "Text" as display.
for the navigation field in BEX settings we are having "Key" as display.
while running the reports in the variable selection list for some reports we having both KEY and text for selection and for others only text are displayed,
we have checked the BEX settings in field and query level there are same.
Please help us here.Check the setting again in the Query level and then maku sure you save it. Come out of the query and then re-open the query and execute, you can see the chages in the output.
-
Select records based on first n distinct values of column
I need to write a query in plsql to select records for first 3 distinct values of a single column (below example, ID )and all the rows for next 3 distinct values of the column and so on till the end of count of distinct values of a column.
eg:
ID name age
1 abc 10
1 def 20
2 ghi 10
2 jkl 20
2 mno 60
3 pqr 10
4 rst 10
4 tuv 10
5 vwx 10
6 xyz 10
6 hij 10
7 lmn 10
so on... (till some count)
Result should be
Query 1 should result --->
ID name age
1 abc 10
1 def 20
2 ghi 10
2 jkl 20
2 mno 60
3 pqr 10
query 2 should result -->
4 rst 10
4 tuv 10
5 vwx 10
6 xyz 10
6 hij 10
query 3 should result -->
7 lmn 10
9 .. ..
so on..
How to write a query for this inside a loop.Hi,
So, one group will consist of the lowest id value, the 2nd lowest and the 3rd lowest, reggardless of how many rows are involved. The next group will consist of the 4th lowest id, the 5th lowest and the 6th lowest. To do that, you need to assign numbers 1, 2, 3, 4, 5, 6, ... to the rows in order by id, with all rows having the same id getting the same number, and without skipping any numbers.
That sounds like a job for the analytic DENSE_RANK function:
WITH got_grp_id AS
SELECT id, name, age
, CEIL ( DENSE_RANK () OVER (ORDER BY id)
/ 3
) AS grp_id
FROM table_x
SELECT id, name, age
FROM got_grp_id
WHERE id = 1 -- or whatever number you want
;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
See the forum FAQ {message:id=9360002} -
I know this is basic, and I've run Logic 7 on my Powerbook for 2 years, but I've purchased a new computer and am unable to figure out what I'm doing wrong in regards to selecting "record" for the Audio channels.
The Mute "M" and Solo "*" appear, but not the Record "R"... any ideas on what I'm overlooking? I've tried setting, and re-setting the Record Path, but nothing I've tried has worked.
Appreciate any and all ideas, comments, etc.
Peace!Right click on the track header->configure track header->choose the options you wish to be displayed in the track header->recording is one of those options->done
-
Select one record for each member of the group
Hi,
am having a table where in i will be having data for so many group members. i need to fetch data for a particular group members whose number of rows of data may be more in numbers (but i want only one row of data for each member of the group)
here is the query for fetching all rows of data
select RI.RESOURCE_NAME,TR.MSISDN,TR.ADDRESS1_GOOGLE, TR.MSG_DATE_INFO, FROM TRACKING_REPORT TR, RESOURCE_INFO RI
WHERE TR.MSISDN IN (SELECT MSISDN FROM RESOURCE_INFO WHERE GROUP_ID ='1' AND COM_ID=2 ) AND RI.MSISDN=TR.MSISDN
order by MSG_DATE_INFOoutput of this query is...
>
ddd 12345 13-Mar-10 19:43:03
eee 54321 Tamil Nadu, India 13-Mar-10 19:39:48
ddd 12345 13-Mar-10 19:32:58
eee 54321 Tamil Nadu, India 13-Mar-10 19:30:07
ddd 12345 13-Mar-10 19:23:08
eee 54321 Tamil Nadu, India 13-Mar-10 19:20:14
fff 98765 13-Mar-10 19:19:22
ddd 12345 13-Mar-10 19:13:01
eee 54321 Tamil Nadu, India 13-Mar-10 19:09:50
ddd 12345 13-Mar-10 19:02:56
eee 54321 tn,ind 13-Mar-10 18:59:49
ddd 12345 13-Mar-10 18:53:08
eee 54321 tn,ind 13-Mar-10 18:49:50
ddd 12345 13-Mar-10 18:42:56
eee 54321 tn,ind 13-Mar-10 18:39:50
ddd 12345 13-Mar-10 18:33:00
eee 54321 tn,ind 13-Mar-10 18:29:50
ddd 12345 13-Mar-10 18:22:54
eee 54321 tn,ind 13-Mar-10 18:19:50
ddd 12345 13-Mar-10 18:12:56
eee 54321 tn,ind 13-Mar-10 18:09:50
ddd 12345 13-Mar-10 18:02:54
eee 54321 tn,ind 13-Mar-10 18:00:02
fff 98765 Tamil Nadu, India 13-Mar-10 17:59:26
fff 98765 Tamil Nadu, India 13-Mar-10 17:54:26
ddd 12345 13-Mar-10 17:52:56
eee 54321 tn,ind 13-Mar-10 17:49:50
fff 98765 Tamil Nadu, India 13-Mar-10 17:49:25
fff 98765 Tamil Nadu, India 13-Mar-10 17:44:26
ddd 12345 13-Mar-10 17:42:56
>
from this output i want only one latest record for each member(ddd,eee,fff). i.e
>
ddd 12345 13-Mar-10 19:43:03
eee 54321 Tamil Nadu, India 13-Mar-10 19:39:48
fff 98765 13-Mar-10 19:19:22
>
how to modify the query to achieve this...?Hi,
This is not giving the result which i want...
table is
CREATE TABLE TRACKING_REPORT
ID NUMBER,
MSISDN NUMBER(12) NOT NULL,
X NUMBER(15,8) NOT NULL,
Y NUMBER(15,8) NOT NULL,
TIME_STAMP DATE,
MSG_DATE_INFO DATE DEFAULT sysdate,
ADDRESS1_GOOGLE VARCHAR2(400 BYTE),
ADDRESS2_GOOGLE VARCHAR2(400 BYTE),
ADDRESS_MLINFO VARCHAR2(400 BYTE),
REQ_ID VARCHAR2(30 BYTE)
CREATE TABLE RESOURCE_INFO
RESOURCE_ID NUMBER,
MSISDN NUMBER,
RESOURCE_NAME VARCHAR2(25 BYTE),
ADDRESS VARCHAR2(100 BYTE),
COM_ID VARCHAR2(20 BYTE),
ADMIN_ID NUMBER,
TIME_STAMP DATE DEFAULT SYSDATE,
GROUP_ID NUMBER
) -
Download only selected record from ALV
Hi
I want to download only selected records from ALV output with button.
i hav to fix the button on ALV screen using &ZDL whenever user presses the button record should be downloaded.
Pl with coding
its very very urgent.Hi ,
i dont have the exact code which suits to your requirement
but declare the internal table
like
data: begin of itab occurs 0,
check type c,
fields
end of itab.
while filling the field catalog
fieldcatalog-checkbox = 'X'
for this check field.
and display the grid
now write this subroutine
*& Form USER_COMMAND
Called from within the ALV processes. Currently, '&IC1' is used
to process the hotspot and display the document 'picked' by the
user.
PV_UCOMM contains the sy-ucomm from ALV
SELFIELD is a structure that contains all the data required to
process a user selection. The following is an example
of the SELFIELD structure and sample values:
FORM USER_COMMAND USING PV_UCOMM LIKE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
CASE PV_UCOMM.
WHEN '&IC1'.
loop at itab where check = 'X'.
append all these records to another internal table itab1
endloop.
call function gui_download.
pass the internal table itab1 in the tables statement
and also you have to give the file path that may be static or dynamic
if dynamic you have to call the function module
f4_filename
and get the filename and pass the same value to gui_download
that will be download to the above said path
endcase.
end form.
reward points if helpful,
thanks & regards,
venkatesh -
Crystal Report Formula to select Record of only MAX Value
hi Everyone,
i need a simple crystal report formula to select one department whose recived quantity Maximum.
for example:
itemcode dscription departmen op recived issue
1 a ab 2 2 2
1 a bb 0 2 2
1 a bc 4 8 2
1 a cc 2 2 2
i group by item the item show just once but i want a formula to show one department who's recived quantity is maximum.i suppress the detail section.and just show the group footer/
itemcode dscription departmen op recived issue
1 a bc 8 14 8Thanks
Re: Crystal Report Formula to select Record of only MAX Value
Abhilash Kumar -
SQL select all sessionid for which ONLY exist actionid 1 OR 2 OR 5
Create Table:
create table x ( sessionid number, actionid number, sessionactionid number, a3 varchar2(10));
Inserts;
insert into x values (1000, 1, 100, 'asdfsadf' );
insert into x values (1000, 2, 101, 'asdfsadf' );
insert into x values (1000, 3, 102, 'asdfsadf' );
insert into x values (1000, 4, 103, 'asdfsadf' );
insert into x values (1001, 1, 104, 'asdfsadf' );
insert into x values (1001, 3, 105, 'asdfsadf' );
insert into x values (1001, 6, 106, 'asdfsadf' );
insert into x values (1001, 1, 107, 'asdfsadf' );
insert into x values (1001, 1, 108, 'asdfsadf' );
insert into x values (1002, 1, 109, 'asdfsadf' );
insert into x values (1002, 2, 110, 'asdfsadf' );
insert into x values (1002, 5, 111, 'asdfsadf' );
insert into x values (1003, 1, 112, 'asdfsadf' );
insert into x values (1003, 2, 113, 'asdfsadf' );
insert into x values (1003, 5, 114, 'asdfsadf' );
insert into x values (1003, 4, 115, 'asdfsadf' );
insert into x values (1004, 2, 116, 'asdfsadf' );
insert into x values (1004, 5, 117, 'asdfsadf' );
Query to resolve;
select all sessionid for which ONLY exist one actionid for each of 1 and 2 and 5
also important that all 3 actionid must exist for that sessionid otherwise that record is not valid for us.
with the table above the result should be;
SESSIONID
=======
1002
PS: Sorry my db is not accessible at the moment and therefore could not test the above CREATE and INSERTS statements.
Edited by: Andre on Jan 19, 2012 5:17 PMHi, Andre,
Andre wrote:
Create Table:
create table x ( sessionid number, actionid number, sessionactionid number, a3 varchar2(10));
Inserts;
insert into x values (1000, 1, 100, 'asdfsadf' );
insert into x values (1000, 2, 101, 'asdfsadf' );
insert into x values (1000, 3, 102, 'asdfsadf' );
insert into x values (1000, 4, 103, 'asdfsadf' );
insert into x values (1001, 1, 104, 'asdfsadf' );
insert into x values (1001, 3, 105, 'asdfsadf' );
insert into x values (1001, 6, 106, 'asdfsadf' );
insert into x values (1001, 1, 107, 'asdfsadf' );
insert into x values (1001, 1, 108, 'asdfsadf' );
insert into x values (1002, 1, 109, 'asdfsadf' );
insert into x values (1002, 2, 110, 'asdfsadf' );
insert into x values (1002, 5, 111, 'asdfsadf' );
insert into x values (1003, 1, 112, 'asdfsadf' );
insert into x values (1003, 2, 113, 'asdfsadf' );
insert into x values (1003, 5, 114, 'asdfsadf' );
insert into x values (1003, 4, 115, 'asdfsadf' );
insert into x values (1004, 2, 116, 'asdfsadf' );
insert into x values (1004, 5, 117, 'asdfsadf' );
Query to resolve;
select all sessionid for which ONLY exist one actionid for each of 1 and 2 and 5
also important that all 3 actionid must exist for that sessionid otherwise that record is not valid for us.
with the table above the result should be;
SESSIONID
=======
1002Why isn't 1003 included? It has only 1 each of 1, 2, and 5, and it has all 3 of those actionids.
This does what you requested:
SELECT sessionid
FROM x
WHERE actionid IN (1, 2, 5)
GROUP BY sessionid
HAVING COUNT (actionid) = 3
AND COUNT (DISTINCT actionid) = 3
;This does not assume anything is uniue.
Did you mean that the sessionids displayed must not have any actionids other than 1, 2 and 5? If so:
SELECT sessionid
FROM x
GROUP BY sessionid
HAVING COUNT (actionid) = 3
AND COUNT (DISTINCT actionid) = 3
AND COUNT ( CASE
WHEN actionid IN (1, 2, 5)
THEN 1
END
) = 3
;Either way, GROUP BY ... HAVING is a natural way to approach the problem. You're interested in groups of rows, not single rows (that's what GROUP BY is all about), and the group as a whole must meet certain conditions (that's what HAVING is all about).
Edited by: Frank Kulash on Jan 19, 2012 11:22 PM
Added 2nd guess -
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 ;) -
Need single record for single period. Modify the select query.
Requirement
THere are 6 programs for each company for each billing period. If anyof the program for one billing period and period_balance>0 then display outstanding balance YES. if period_balance <=0 for all the programs for one period then outstanding balance=NO
Below is the query i have used but i have to modify the query to get single record for each period whether outstandignbalance yes or no. Please help to resolve this issue. OR modify the query.
select distinct B_Billing_key, B_COMPANY_ID company ,
to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') Billing,
Max(to_char(P_RECEIVED_DATE,'MM/DD/YY')) lastPaymentdate,
SURCH_AMOUNT,ADJUST_AMOUNT,PI_AMOUNT,AMOUNT,
(nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))"Period_Balance",
decode(sign((nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))),1, 'Yes'
,'No'
) outstandingbalance
p.PROGRAM_NAME_ID programname
FROM tuff_balance_view,MV_PROG_SURCH S,MV_PAYMENT_HOLDING H,MV_PROGRAM_DICT P where
b_company_id = 'U-7052-C'
and B_Billing_key=s.BILLING_KEY
and S.PROGRAM_KEY = P.PROGRAM_KEY
and P.PROGRAM_KEY= H.PROGRAM_KEY
GROUP BY B_Billing_key,B_COMPANY_ID,B_REPORT_PERIOD,SURCH_AMOUNT,ADJUST_AMOUNT,PI_AMOUNT,PROG_SURCH_KEY,
S.PROGRAM_KEY,p.PROGRAM_NAME_ID,AMOUNT
order by B_Billing_key desc
B_Billing_key is the primary key. I am looking for the output only one record for each biling perid. there are 6 programs for each billing period. if any of the program has period balance >0 then outstanding balance should be yes. For sample i am giving 2 programs.
Actual output from the above
biling_key company billing period period_balance outstandingbalance programname
123 xyz January 2011 $4 Yes ABC
123 xyz January 2011 $-5 NO DEF
456 xyz February 2011 $-3 NO ABC
456 xyz February 2011 $- 2 NO DEF
Need the output as below from the above query. Can you please help to simplify query. If anyof theprogram having outstanding balance for that particular period show the outstandigbalance as yes. Else NO.
Expected output as below
company billing period outstandingbalance programname
xyz January 2011 Yes ABC
xyz February 2011 No DEF
Thanks,
viHi G,
With the same query i am gettting outs as NO for all months which is not true. can you pelase look at the following data.
SELECT DISTINCT B_BILLING_KEY,
to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') Billing,
B_company_id company,
sum((nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))) "PeriodBalance",
Max(to_char(P_RECEIVED_DATE,'MM/DD/YY')) LastPaymentDate,
decode(sign(
(nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))), 1,'Yes','No') Outs
FROM mv_program_dict P, tuff_balance_view T WHERE
b_company_id = 'U-7052-C' group by B_REPORT_PERIOD,B_company_id,B_BILLING_KEY,B_ORG_SURCH_AMOUNT,
B_ORG_PI_AMOUNT,P_AMOUNT
order by B_BILLING_KEY desc
Actual
Billing key Billing company periodbalance lastpayment date outs
110631534073 November 2010 U-7052-C 270 Yes
110631534073 November 2010 U-7052-C 690 Yes
110631534073 November 2010 U-7052-C 66 Yes
110461533197 October 2010 U-7052-C 4740 Yes
110461533197 October 2010 U-7052-C 27000 Yes
110461533197 October 2010 U-7052-C 0 No
110251532527 September 2010 U-7052-C 0 09/13/10 No
110251532527 September 2010 U-7052-C 0 No
110251532527 September 2010 U-7052-C -18 09/13/10 No
110251532484 August 2010 U-7052-C 0 09/13/10 No
110251532484 August 2010 U-7052-C 2001 09/13/10 Yes
110251532484 August 2010 U-7052-C 0 No
Expectedoutput(need only following columns)
Billing key Billing company lastpayment date outs
110631534073 November 2010 U-7052-C Yes
110461533197 October 2010 U-7052-C Yes
110251532527 September 2010 U-7052-C 09/13/10 No
110251532484 August 2010 U-7052-C 09/13/10 YES
By using below query i am getting all output as NO. HOw to modify it.
SELECT company,
billing,LastPaymentDate,
CASE
WHEN SUM (DECODE (outs, 'YES', 1, 0)) > 0 THEN 'YES'
ELSE 'NO'
END Outstanding
FROM (
SELECT DISTINCT B_BILLING_KEY,
to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') Billing,
B_company_id company,
sum((nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))) "PeriodBalance",
Max(to_char(P_RECEIVED_DATE,'MM/DD/YY')) LastPaymentDate,
decode(sign(
(nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))), 1,'Yes','No') Outs
FROM mv_program_dict P, tuff_balance_view T WHERE
b_company_id = 'U-7052-C' group by B_REPORT_PERIOD,B_company_id,B_BILLING_KEY,B_ORG_SURCH_AMOUNT,
B_ORG_PI_AMOUNT,P_AMOUNT
order by B_BILLING_KEY desc)
GROUP BY company, billing,LastPaymentDate;
Note:in the actual out put max(lastpayment date) is returing null values. if there is any date in one billing return that date only remove null example is september. in september it should return only 09/13/10 this date not null date. but if there is no other within one biling then consider that as null example november..
Thanks,
v -
Make Record for folder and multi-selected files
Hi,
'Make Record' item disappeared in MENU for folders not for files.
And it can't make record for multi-selected files.
I can only make Record by one and one.
How to make Records for folder and multi-selected files?
Regards
KitaeProgramatically, only a single document at a time can be made a record :-
makeRecord
public Item makeRecord(long parentId,
long docId,
NamedValue[] attrs,
AttributeRequest[] attributes)
throws FdkException
You could potentially through a custom workflow triggered on UserRequest allow multiple submitted documents to be made records through a custom BPEL process calling Content DB Web Services.
Matt.
Maybe you are looking for
-
Started w/FF 29 something.on Win XP (Home) SP3 Verified w/Task manager and PS that there is no other instance of FF. Occurs only in my profile, administrator and other users do not get this message. First Resetting, did not work. Safe mode also did n
-
RunTimeEngine linked to my application
I would like to know what are the possibility with executable file built with LabVIEW. Is it possible to compile our application with the RunTimeEngine linked to it. Why other version of LabVIEW's executable are not supported by the latest RTE. Thank
-
How to Instal the etsy Mini store on my Iweb website?
Hi I'm a Fashion designer and I would like to link the etsy shop I have to my iWeb site. Does anyone know how? thanks! Miriam www.mir-handbags.com
-
Acceptable uris for edit mode in portlets
Hi, I have been experimenting with setting URIs for edit mode in portlets. It seems that the only two acceptable types of URI are those in the portal project and those that point to a file in the filesystem. It does not seem possible to forward on to
-
Hi, I have an existing web application (html/jsp) that needs to be put behind SSO. I have found out that this works with the following steps: - edit web.xml: add logical roles, define url rules and assign roles to url rules - deploy the app to 9iAS a