many need help query step
Hi I met a problem while making this request.
I'm doing the query shows how many customers entered into a table of rental during the set time that I choose.
I am tempted to cross reference it with the amount of customers stored in the original customer table since the beginning of time.
That's what I came with, but I get the error that I have successfully completed my Sql
SELECT * FROM RENTAL WHERE RENTAL_DATE > = 1 January 14 ' AND RENTAL_DATE < = 10 January 14 ',.
COUNT (DISTINCT CUST_ID) AS NUMBEROFCUSTOMERS,
SELECT COUNT (DISTINCT CUST_ID) AS TOTALCUSTOMERS CUSTOMER
The top and the bottom of line work separately from this, but when I add the line in the Middle I have no chance.
Thanks in advance
First of all, ' 01-JAB-14' is not a date - it's a chain. Anyway, you can use an outer join:
SELECT COUNT (DISTINCT C.CUST_ID) DID TOTALCUSTOMERS,
COUNT (DISTINCT R.CUST_ID) AS TOTALRENTERS
CUSTOMER C,.
RENTAL R
WHERE C.CUST_ID = R.CUST_ID (+)
AND R.RENTAL_DATE (+) > = DATE ' 2014-01-01'
AND RENTAL_DATE (+)<= date="">=>
/
Or:
SELECT COUNT (CUST_ID) AS TOTALCUSTOMERS.
MAX)
(
SELECT COUNT (DISTINCT CUST_ID)
RENTALS
WHERE RENTAL_DATE > = DATE ' 2014-01-01'
AND RENTAL_DATE<= date="">=>
)
) AS TOTALRENTERS
OF THE CUSTOMER
/
SY.
Tags: Database
Similar Questions
-
Hey guys,.
I have a question that I can't wrap my head around. I have a table called traffic, and in this table I have tons of columns... I focus mainly on three pillars, VIOLATIONTYPE, TID, AND guid. When a judgment is made, it receives a uniqueIdm which is the GUID column.
If more than one ticket is given to the individual, the guid remains the same. I need to write a query to find out how many warnings is emitted by the user who is TID column.
The problem is, if more than one ticket has been assigned at the time of the stop and these tickets are not only attention, but also a quote, I won't count that stops traffic in my query.
I just need all the stops that are strictly warnings.
Of course, I know how to extract the warnings, but if the guid is a warning and reference both, I don't know how to remove the records in the query. Any help would be appreciated. The query below, I wrote is just the initial steps to get * him to stop before I eliminate records where a quote and a caveat had the same GUID...
Select * from traffic where tid = "1234" and violationtype = "warning" and guid in (select traffic seq_guid b where a.guid = b.guid)Consider using a NOT IN or NOT EXISTS a subquery to allow lines with citations, something like (not tested)
select * from traffic a where tid='1234' and violationtype = 'warning' and guid in (select seq_guid from traffic b where a.guid = b.guid) and not exists (select 0 from traffic c where c.guid = a.guid and violation_type = 'citation')
-
Need help query view with the 'Level' column name
Hello world
I use Oracle DB 10 g
I have this request
XXITS_EMP_MSTR_V is a view created by someone else.SELECT count(per_id) FROM XXITS_EMP_MSTR_V WHERE per_id = 213214 AND Level='Technical Staff / Officer'
I get the error "ORA-01788: CONNECT BY clause in this query block" for the the above statement.
Is it possible that I can always get the result without changing the view?
Any help is appreciated...
Thank you
ElmerElmer says:
Hello worldI use Oracle DB 10 g
I have this request
SELECT count(per_id) FROM XXITS_EMP_MSTR_V WHERE per_id = 213214 AND Level='Technical Staff / Officer'
Place the level with quotes
AND "Level" = 'Technical Staff / Officer'
Make sure that the case is used correctly when using double quotes.
-
Have the rank as below,
name of the sum
100 A1
-A2 200
A3 300
50 A1
-A2 700
A3 80
10 A1
-A2 90
30 A3
Need to query to extract the output like this:
B1 B2
A1 + a3 (Sum) A2 (sum)
Please help me out of this...
Hello
It is difficult to understand what you want... A guess based on many assumptions:
-B1 and B2 are column headers,
-"A1 + A3" and "A2" in the 'exit' is simply to indicate that you want the sum of the amounts for the first names.-Some of the AI have all their amounts > = 0, others have their amounts<=>=>
-You want to make the sum of all positive numbers in the first column and all the negatives in the second columnSELECT SUM (GREATEST (0, t.amount)) b1
, B2 SUM (LESS (0, t.amount))
MYTABLE t
;
(I think there is only a bit of luck it's really what you want, but provide a full test case and the output that you really want and why not, try to explain / explicit rules, then we can give better help)
Best regards
Bruno Vroman.
-
Need help for query flat_file type clobdata oracle table data.
Hi Sir,
I need help to query oracle table flat file data having given clob type.
COLUMN FOR CHAR_DATA FLAT_FILEOracle Version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product PL/SQL Release 10.2.0.1.0 - Production "CORE 10.2.0.1.0 Production" TNS for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production Source table CREATE TABLE order_details ( QUEUE_SEQNUM NUMBER(10,0) NOT NULL ENABLE, LINE_SEQNUM NUMBER(10,0) NOT NULL ENABLE, CHAR_DATA CLOB, OPTIMISTIC_LOCK_KEY NUMBER(20,0) )
EXPECTED RESULTS:EU,6067AT,AT10,000000402004,NexiumGERDManagementProject,Z435,,ZZ29,NIS-GOLD,AT EU,6067AT,AT10,000000402038,NIS-OEU-ARI-2007/1,Z450,,ZZ29,NIS-OEU-ARI-2007/1,AT EU,6067AT,AT10,000000402039,SymbicortNISinCOPD,Z450,,ZZ29,NIS-REU-DUM-2007/1,AT EU,6067AT,AT10,000000402040,D1443L00044SeroquelXRRuby,Z450,,ZZ29,D1443L00044,AT EU,6067AT,AT10,000000402041,NIS-GEU-DUM-2008/1,Z450,,ZZ29,NIS-GEU-DUM-2008/1,AT EU,6067AT,AT10,000000402042,SonstigeAktivitätenLCM,Z450,,ZZ29,.,AT EU,6067AT,AT10,000000402134,D1680L00002Saxagliptin,Z450,,ZZ29,D1680L00002,AT EU,6067AT,AT10,000000402199,SeroquelWaveNIS,Z450,,ZZ29,NIS-NEU-DUM-2009/1,AT EU,6067AT,AT10,000000402313,SeroquelExtra(D1443L00082),Z450,,ZZ29,D1443L00082,AT EU,6067AT,AT10,000000402517,AtlanticD5130L00006(AZD6140),Z450,,ZZ29,D5130L00006,AT EU,6067AT,AT10,000000554494,ArimidexSt.Gallen(13+2),Z142,,ZZ09,,AT EU,6067AT,AT10,000000554495,ArimidexASCO(5delegates),Z142,,ZZ09,,AT EU,6067AT,AT10,000000554496,ArimidexSanAntonio6delegates,Z142,,ZZ09,,AT EU,6067AT,AT10,000000554497,ArimidexBreastCancerSummit(13+2),Z130,,ZZ09,,AT EU,6067AT,AT10,000000554498,ArimidexEIH(15delegates),Z130,,ZZ09,,AT EU,6067AT,AT10,000000554499,ArimidexNIFA(200delegates),Z135,,ZZ09,,AT EU,6067AT,AT10,000000554500,ArimidexNIFAworkshops(8x25),Z135,,ZZ09,,AT EU,6067AT,AT10,000000554501,ArimidexPraktischeGyn.Fortbildung,Z147,,ZZ09,,AT EU,6067AT,AT10,000000554502,ArimidexAGO,Z147,,ZZ09,,AT EU,6067AT,AT10,000000554503,ArimidexHämato/OnkologieKongress,Z147,,ZZ09,,AT EU,6067AT,AT10,000000554504,ARIMIDEXGYNäKOLOGENKONGRESS,Z147,,ZZ09,,AT EU,6067AT,AT10,000000554505,ArimidexChirurgenkongress,Z147,,ZZ09,,AT
AFFIRM_CODE COMPANY_CODE INTERNAL_ORDER_CODE INTERNAL_ORDER_DESC ENIGMA_ACTIVITY SUB_ACTIVITY_CODE IN_AFF_IND ORDER_TYPE EXTERNAL_ORDER COUNTRY EU 6067AT AT10 000000402004 NEXIUMGERDMANAGEMENTPROJECT Z435 NULL ZZ29 NIS-GOLD AT EU 6068AT AT11 000000402005 NEXIUMGERDMANAGEMENTPROJECT Z435 NULL ZZ29 NIS-GOLD AT
Sorry, my bad. Without database at hand, I'll try 'baby steps' (borrowed from Frank) so you don't confuse it with errors that I might add (happens far too often already, but at least you won't "swallow" as forum members think is one of the main goals of this fighter - help her learn - providing not only the proverbial fish.)
Search the Forum - your problem is one of its best sellers. Watching {message identifier: = 10694602} ("split string into" was the key word used in research) you can try something asselect table_row, level clob_row, regexp_substr(char_data,'[^' || chr(13) || chr(10) || ']+',1,level) the_line from (select to_char(queue_seqnum)||':'||to_char(line_seqnum) table_row, char_data from order_details ) connect by regexp_substr(char_data,'[^' || chr(13) || chr(10) || ']+',1,level) is not null and prior char_data = char_data and prior table_row = table_row and prior sys_guid() is not null
to get all the s the_lineall CLOB and after that the use of the example even to get your columns of each the_line.
Concerning
Etbin
Edited by: Etbin on 3.2.2013 09:01
.. .but I m connected to do things according to the instructions, I can't do something.
Used to happen to me too and I did as told to the but only after explaining any disadvantages, I was aware of in time. The last sentence is usually: "O.K. now be just and Don't come back with that kind of thing when it turns out that this isn't the right thing."
rp0428 post - something to remember. -
Oracle Version: 11.2.0.2.0
I need assistance with the output of the query. Here is the table.
With Tbl_Nm as
(
Select 'ABC1' SYSTEM_ID, REGION 'US', 'CHI' SUB_REGION 4000 BALANCE, to_date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') LAST_UPD_TIME, 'A' FLAG of union double all the
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select * from tbl_nm
I need the output below.
PQR2 UK MC 2600 1 OCTOBER 2012 04:45
ABC1 US NY 3500 October 1, 2012 06:45
LMN3 UK BT 2500 November 1, 2012 07:45
The need the disc according to this system_id flagged as "A". But if the last disc of 'd' then it must show that the amount, but the file should be displayed in 'A '.
I've tried a few and got stuck. Help, please. Not able to get a balance '.
This question is a bit similar to needing help with a query result
With Tbl_Nm as
(
Select 'ABC1' System_Id, region 'US', 'CHI' Sub_Region, 4000 balance, To_Date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') Last_Upd_Time, 'A' flag of double Union All
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select System_Id, region, Sub_Region, Balance, Last_Upd_Time of Tbl_Nm T1
where t1. Last_Upd_Time = (select max (Last_Upd_Time) in the Tbl_Nm T2 where T1.) SYSTEM_ID = T2. SYSTEM_ID)
So maybe you'd then
ORDER BY DECODE(flag,'D',9,1) ASC...
to get the Ds at the end of the list.
or
ORDER BY CASE WHAT flag = has ' (your other filters) AND then 9 or 1 end CSA,...
HTH
-
Hello
I have a data in table (raj_table) with columns (char11) raj_id, raj_number (varchar2 (15)), raj_format (NUMBER), Primary_ID (identity with the values of the primary key column)
Primary_ID raj_id Raj_number Raj_format
1 raj rajvend 1
2 raj rajvend 1
3 raj rajvendor1 2
4 raj rajvendor1 2
5 raj rajvendor1 2
6 raj rajvendor2 3
I used under SQL to get query output as below, but has not achieved the required result:
Select client_id vendor_number, vendor_format, primary_id, row_number() on sl_no (client_id partition, primary_id, vendor_format order of client_id primary_id, vendor_format, vendor_number, vendor_number)
from raj_table by sl_no asc
SL_NO raj_id raj_number raj_format primary_id
1 1 raj rajvendor 1
1 2 raj rajvendor 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 3
I need help with a SQL query to get the result as above without using the group by clause. I want to bring together the combination of separate line of the three columns (raj_id, raj_number, raj_format) and add a unique serial number for each online game (SL_NO column below). So, above there are 3 unique set of (raj_id, raj_number, raj_format) I can get in a group by clause, but I can not add prmiary_id, SL_NO values if I group by clause. I used the analytical functions like row_number() but no luck. Need solution for this.
with t as)
Select 'raj' raj_id, 'rajvend' raj_number, 1 raj_format, 1 primary_id Union double all the
Select option 2, 'raj', 'rajvend', 1 double Union all
Select 3, 'raj', 'rajvendor1', 2 double Union all
Select 4, 'raj', 'rajvendor1', 2 double Union all
Select 5, 'raj', 'rajvendor1', 2 double Union all
Select 6, 'raj', 'rajvendor2', 3 double
)
Select dense_rank() over (order of raj_id, raj_number, raj_format) sl_no,
t.*
t
order by primary_id
/
PRIMARY_ID RAJ RAJ_NUMBER RAJ_FORMAT SL_NO
---------- ---------- --- ---------- ----------
1 1 raj rajvend 1
1 2 raj rajvend 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 36 selected lines.
SQL >
SY.
-
I am a novice. I need to know, STEP BY STEP, how to license and buy a picture. Help, please!
1: search for your image
2: click on an image you want
3: click the link to the image in the license
Really, that's all there is to it ;-)
-
I need help with a simple query in an ORACLE database. I tried a lot of things that I found on the internet, but none of them worked for me.
The following query retrieves four lines:
SELECT sampled_date AS VALUE1, VALUE2 AS result, 0 as value3
Of asw_lab
WHERE template_result = 'A' AND analysis = 'B' AND ROWNUM < 5
ORDER BY sampled_date DESC;
I would like to calculate a moving average of the last four values with the date of the sample of the last line.
For example, I have this result for the query above:
Value1 value2 value3
01/04/14-16:00 1 0
01/04/14 15:00 2 0
01/04/14 14:00 3 0
01/04/14 13:00 4 0
I want to extract the below my average/query calculation result:
Value1 value2 value3
01/04/14-16:00 2.5 0
Can you help me create a request to that effect?
Thank you
Maybe it's
Select max (VALUE1) VALUE1, VALUE2 avg (VALUE2), avg (VALUE3) value3
Of
(
SELECT sampled_date AS VALUE1, VALUE2 AS result, 0 as value3
Of asw_lab
WHERE template_result = 'A' AND analysis = 'B' AND ROWNUM<>
)
-
Need help with query Cumulative difference
Hi all
I need help with a query and my requirement is as below
{code}
ROWNO ORDERS VALUE 1 10 900 2 11 700 3 12 500 4 13 400 {/ code}
I have need to query which will display the cumulative difference for example I value tell 10000 numbers opening
now I need for each of the lines of cumulative difference
{code}
ROWNO ORDERS DIFF
1 10 10000 - 900 = 9100
2 11 9100 - 700 = 8400
3 12 8400 - 500 = 7900
4 13 7900 - 400 = 7500
{/ code}
WITH commands LIKE (10 SELECT order_id, 900 double UNION ALL val
11. SELECT, 700 FROM dual UNION ALL
SELECT 12, 500 FROM dual UNION ALL
Select 13, 400 double)SELECT row_number() over (ORDER BY order_id ASC) AS rowno
order_id
sum (val) 10000 - OVER (ORDER BY order_id ASC) AS diff
orders/
HTH
-
With the help of Windows 10, not all pdf documents launch Adobe Reader DC. As a result, I have not all normally available printing options. How can I get Reader to open the default player. I need to clear, step-by-step instructions, please. Thank you
Hello
Please visit the following link to set the reader as default PDF reader.
Restoration of Adobe Acrobat Reader in the default PDF Viewer
Concerning
Sukrit diallo
-
I need assistance in the import of certain vectors, watercolor color chart and other creative market (step by step instructions). Im a newbie to Illustrator and need help.
Should be the subject of the file > open. After the download. The swatches will come with the file.
-
Need help with query between 2 dates
Hello
I did not SEE in a long time and need help with a simple query.
I have a table of DB access with 3 fields, name, date and number
What I want is to create a query to retrieve all the names between 2 dates
When I ask the date field, the results are showing in this formats 2013-07-12 00:00:00
Here's my query
< cfquery datasource = 'mydb' name = 'test' >
SELECT name from myTable
where edate between ' 2011-01-01 00:00:00 ' AND ' 2013-01-01 00:00:00 '
< / cfquery >
< cfoutput query = 'test' >
#name #.
< / cfoutput >
What I get is this error
ODBC = 22005 (assignment error) error code
[Microsoft] [ODBC Microsoft Access driver] Type mismatch of data in the expression of the criteria.
Don't know what I'm doing wrong here.
Please let me know.
Thank you
SELECT ename
FROM MyTable
WHERE edate BETWEEN
AND
#ename #.
-
Hello
I need help to form a query. I have two tables Support_issues and Support_comments with the information below.
I want to create a query to view the account of the situation for the last 15 days until today.
Sample Input data support_issues: ISSUE_ID ISSUE_DESC CREATION_DATE STATUS 1 AAA 01/NOV/2011 Open 2 BBB 02/NOV/2011 Closed 3 CCC 02/NOV/2011 Open 4 DDD 03/NOV/2011 Reopened 5 EEE 03/NOV/2011 Reopened support_comments: COMMENT_ID ISSUE_ID COMMENT_DESC STATUS UPDATE_TIME 101 1 aaa Open 01/NOV/2011 102 2 bbb Open 02/NOV/2011 103 2 bbbbbb Closed 03/NOV/2011 104 2 bbbb11 Reopened 03/NOV/2011 105 3 ccc Open 02/NOV/2011 106 2 bbbbb Closed 03/NOV/2011 107 4 ddddd Open 03/Nov/2011 108 5 eeeee Open 03/NOV/2011 109 4 343434 Closed 06/NOV/2011 110 4 dfdf Reopened 07/NOV/2011 111 5 dfdfdf Closed 08/NOV/2011 112 5 udehjk Reopened 10/NOV/2011
For "Created" count of status must be taken Support_issues table, for others it must be taken from table Support_comments.Sample output: DATE Created Reopened Closed 28/OCT/2011 0 0 0 29/OCT/2011 0 0 0 30/OCT/2011 0 0 0 31/OCT/2011 0 0 0 01/NOV/2011 1 0 0 02/NOV/2011 2 0 0 03/NOV/2011 2 1 2 04/NOV/2011 0 0 0 05/NOV/2011 0 0 0 06/NOV/2011 0 0 1 07/NOV/2011 0 1 0 08/NOV/2011 0 0 1 09/NOV/2011 0 0 0 10/NOV/2011 0 1 0 11/NOV/2011 0 0 0
Please help me to form a query for this!
Thank you
MukeshHello
Try the following query
with t1 as ( select to_char(sysdate-level+1,'dd-mm-yyyy') as date_range from dual where level<16 connect by sysdate-16
Cannot test because I did not create, insert commands...
-
need help for a conditional query
guys this is just. as an extension of this post that Frank was helping me. IM reposting because my needs change slightly and im having a hell of a time trying to change the query.
Here are the previous post.
need help with query can find data back please help.
dataCREATE TABLE "FGL" ( "FGL_GRNT_CODE" VARCHAR2(60), "FGL_FUND_CODE" VARCHAR2(60), "FGL_ACCT_CODE" VARCHAR2(60), "FGL_ORGN_CODE" VARCHAR2(60), "FGL_PROG_CODE" VARCHAR2(60), "FGL_GRNT_YEAR" VARCHAR2(60), "FGL_PERIOD" VARCHAR2(60), "FGL_BUDGET" VARCHAR2(60) )
I need to find the year of greater subsidy for the granting by a period setting.Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');
Once I found the great year, I need to check the value of the period 14 this grant for the previous year and add it to the amount of the budget for this grant. However if there is an entry in the biggest year for period 00 so I need to ignore the period 14 of the previous year and the current calculation period + (current period - more great year 00)
hope that makes sense, so in other words, with the new data above. If I asking me a second period of the grant year 11. I'd end up with $800
because the greatest year is 11 it contains one point 0 with $ 400, so my total should be
amount of period $2,600
period $0 400 - period $2 600 = $200
600 + 200 = $800
If I have question period 1 grant 360055 I'd end up just with 800 grnt year 10.
I tried to edit this query you have provided me with no luck. I tried for several embarrassed day but I'm saying I can just do what im trying to do.
can you please help me.
Here's the query provided by frank kulash who graciously put it together for me.
MiguelWITH got_greatest_year AS ( SELECT fgl.* -- or whatever columns are needed , MAX ( CASE WHEN fgl_period = :given_period THEN fgl_grnt_year END ) OVER () AS greatest_year FROM fgl ) SELECT SUM (fgl_budget) AS total_budget -- or SELECT * FROM got_greatest_year WHERE ( fgl_grnt_year = greatest_year AND fgl_period = :given_period ) OR ( fgl_grnt_year = greatest_year - 1 AND fgl_period = 14 ) ;
Hi, Miguel.
You are waying that when larger year who has: given_period also a period = '00' (or '0', or whatever it is you want to use), then you want to double the budget of the given_period (subtract the '00' budget and do not count '14' year pevious)? If so, add another condition to the CASE statement that decides what you've summarized:
WITH got_greatest_year AS ( SELECT TO_NUMBER (fgl_grnt_year) AS grnt_year , fgl_period , TO_NUMBER (fgl_budget) AS budget , MAX ( CASE WHEN fgl_period = :given_period THEN TO_NUMBER (fgl_grnt_year) END ) OVER () AS greatest_year FROM fgl ) , got_cnt_00 AS ( SELECT grnt_year , fgl_period , budget , greatest_year , COUNT ( CASE WHEN grnt_year = greatest_year AND fgl_period = '00' THEN 1 END ) OVER () AS cnt_00 FROM got_greatest_year ) SELECT SUM ( CASE WHEN grnt_year = greatest_year -- New AND fgl_period = :given_period -- New AND cnt_00 > 0 THEN budget * 2 -- New WHEN grnt_year = greatest_year AND fgl_period = :given_period THEN budget WHEN grnt_year = greatest_year AND fgl_period = '00' THEN -budget WHEN grnt_year = greatest_year - 1 AND fgl_period = '14' AND cnt_00 = 0 THEN budget END ) AS total_budget FROM got_cnt_00 ;
You will notice it is the same as the previous query, I posted, with the exception of 3 lines marked 'new '.
Maybe you are looking for
-
Anonymous UUID: A3EA911B-155A-516D-C842-F126A85CE472 Sat Jun 11 02:50:14 2016 Panic report *. panic (cpu 0 0xffffff8016dce5fa appellant): Kernel trap at 0xfffff38016dc7d4a, type 14 = page fault, registers: CR0: 0X000000008001003B, CR2: 0XFFFFF38016DC
-
Satellite A100-998: Clunks from the HARD disk in just 2 months old
This laptop has just started to make a rattle almost constant light, awkward - probably from the hard drive. No difference to the power of battery or sector. The noise is not related to the DVD at all drive. Moreover, the performance of the computer
-
Prevent the Beep.vi slow down the VI
Hello I'm working on a metronome that should run for a period of x with a frequency of x. The time is in seconds and rate. Whenever there is the beet, the VI must make a beep. This can be done easily by the beep.vi, but the standard for the beep.vi i
-
Admin Username and domain are gone
I tried to add an addiotnal username to my computer a few days ago and now I've lost my user admin account I try to connect to windows, and it's a whole new account. I can't make any changes because I'm not in the administrative account. Of course, I