Help with one query ( Please reply)
Oracle version : 11.2.0.2.0
I have a table with the following set of rows
with Table_dm AS
( select 1 month_no ,'wk1' week, 120 DM_AMT,300 GRoss_Amt,4 Week_no, 12 Gross_qty,1000 dm_adj_total from dual
UNion all
select 1 month_no ,'wk2' week,120 DM_AMT,300 GRoss_Amt,4 Week_no, 12 Gross_qty,1000 dm_adj_total from dual
union all
select 1 month_no ,'wk3' week,120 DM_AMT,300 GRoss_Amt,4 Week_no, 12 Gross_qty,1000 dm_adj_total from dual
union all
select 1 month_no ,'wk4' week,120 DM_AMT,300 GRoss_Amt,4 Week_no, 12 Gross_qty,1000 dm_adj_total from dual
union all
select 2 month_no ,'wk5' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
UNion all
select 2 month_no ,'wk6' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
union all
select 2 month_no ,'wk7' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
UNion all
select 2 month_no ,'wk8' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
UNion all
select 2 month_no ,'wk9' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
So the data in Grid will be like this
month_no
week
DM_AMT
GRoss_Amt
Week_no
Gross_qty
dm_adj_total
DM_ADJ_Final
1
wk1
120
300
4
12
1000
1000 * 300 /(300+400) = 428.57
=1
wk2
120
300
4
12
1000
1000 * 300 /(300+400) = 428.57
1
wk3
120
300
4
12
1000
1000 * 300 /(300+400) = 428.57
1
wk4
120
300
4
12
1000
1000 * 300 /(300+400) = 428.57
2
wk5
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
2
wk6
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
2
wk7
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
2
wk8
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
2
wk9
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
I need to calculate DM_ADJ_Final where calculation for DM_ADJ_Final will be like
= dm_adj_total * gross_amt/ (gross_amt (where month_no =1 ) + gross_amt (where month_no =2 )) ( Please refer DM_ADJ_Final column above for calculation with value )
You apparently have (or intend) an association between rows where month_no = 1 and month_no = 2.
But what is that relationship? Is the month 2 row always 4 weeks later than the month 1 row?
That relationship needs to be spelled out exactly.
month_no
week
DM_AMT
GRoss_Amt
Week_no
Gross_qty
dm_adj_total
DM_ADJ_Final
1
wk1
120
300
4
12
1000
1000 * 300 /(300+400) = 428.57
=1
wk2
120
300
4
12
1000
1000 * 300 /(300+400) = 428.57
1
wk3
120
300
4
12
1000
1000 * 300 /(300+400) = 428.57
1
wk4
120
300
4
12
1000
1000 * 300 /(300+400) = 428.57
2
wk5
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
2
wk6
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
2
wk7
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
2
wk8
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
2
wk9
200
400
5
20
1000
1000 * 400 /(300+400) = 571.42
I need to calculate DM_ADJ_Final where calculation for DM_ADJ_Final will be like
= dm_adj_total * gross_amt/ (gross_amt (where month_no =1 ) + gross_amt (where month_no =2 )) ( Please refer DM_ADJ_Final column above for calculation with value )
Similar Messages
-
Can any one help with this query please
I have a table something as below
Things_t
Things Characteristic Char Value
Item 1 Colour Red
Item 1 Packaging
Item 2 Shape Square
Item 2 Brand Spunk
Now i want to reterive an item with none of its char values as Null. Using the query “ select distinct things from things_t where char value is Null ” will fetch the item 1 also together with item 2. i want to fetch a record from thing for which none of the char values are Null such as Item 2. Can you please help me with this query.Try this:
WITH t AS
(SELECT 1 item_id, 17436 chr_id, 14225034 chr_val_id FROM dual UNION
SELECT 1 item_id, 39 chr_id, 14276173 chr_val_id FROM dual UNION
SELECT 1 item_id, 17774 chr_id, NULL chr_val_id FROM dual UNION
SELECT 1 item_id, 265 chr_id, 20502978 chr_val_id FROM dual UNION
SELECT 1 item_id, 16978 chr_id, 797233 chr_val_id FROM dual UNION
SELECT 1 item_id, 13092 chr_id, 5666917 chr_val_id FROM dual UNION
SELECT 1 item_id, 15228 chr_id, 1209758 chr_val_id FROM dual UNION
SELECT 2 item_id, 112 chr_id, 12705342 chr_val_id FROM dual UNION
SELECT 2 item_id, 6945 chr_id, NULL chr_val_id FROM dual UNION
SELECT 2 item_id, 70 chr_id, 12597376 chr_val_id FROM dual UNION
SELECT 2 item_id, 16832 chr_id, NULL chr_val_id FROM dual UNION
SELECT 2 item_id, 7886 chr_id, 9588619 chr_val_id FROM dual UNION
SELECT 2 item_id, 6986 chr_id, 2659351 chr_val_id FROM dual UNION
SELECT 3 item_id, 9531 chr_id, 8910943 chr_val_id FROM dual UNION
SELECT 3 item_id, 9798 chr_id, 8717531 chr_val_id FROM dual UNION
SELECT 3 item_id, 17446 chr_id, 12266441 chr_val_id FROM dual UNION
SELECT 3 item_id, 4830 chr_id, 13683090 chr_val_id FROM dual UNION
SELECT 3 item_id, 9518 chr_id, 834772 chr_val_id FROM dual UNION
SELECT 3 item_id, 11031 chr_id, 20233753 chr_val_id FROM dual UNION
SELECT 3 item_id, 12564 chr_id, 2282478 chr_val_id FROM dual)
SELECT DISTINCT item_id
FROM t
MINUS
SELECT DISTINCT item_id
FROM t
WHERE chr_val_id IS NULLOr this:
SELECT item_id
FROM (SELECT item_id,
MIN(NVL(chr_val_id, -1)) min_chr_val_id
FROM t
GROUP BY item_id)
WHERE min_chr_val_id != -1Edited by: lee200 on Oct 15, 2012 9:22 AM -
SQL I need help with this query Please help
List the names of all the products whose weight unit measure is “Gram”. Order the list by product name. Do not use JOINS, but use the IN clause with a sub-query.
select Name
from UnitMeasure
where Name= 'Gram'
order by Name
I did this, but it seem that the requirement is different.As a guess:
Select Name from Product
where UnitMeasure in (Select Name from unitmeasure where name = 'Gram')
Andy Tauber
Data Architect
The Vancouver Clinic
Website | LinkedIn
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
"Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread. -
Hi there,
These are the sample values
declare @table table
Name varchar(50),
flag int
insert into @table
values('Matt', 0),
('George', 0),
('George', 1),
('Lucas', 0),
('Jerome', 0),
('Jerome', 1)
I want to select out where George and Jerome where flag = 0 but leave the records from the same names where flag = 1. All others that only have flag = 0, should stay. So only the names that repeat and have both flag, flag = 0 zero should be selected out.
Thanks for your help.So desired output is ????
George 0
Jerome 0
declare @table table
Name varchar(50),
flag int
insert into @table
values('Matt', 0),
('George', 0),
('George', 1),
('Lucas', 0),
('Jerome', 0),
('Jerome', 1)
select name,min(flag) flag,count(*) from @table
group by name
having count(*)>1
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 -
I have a macbook Pro i7 mid november 2010. I am wondering if i can exchange my notebook with the latest one. Can anyone help me out with this query please.
You can sell your existing computer using eBay, Craigslist or the venue of your choice. You could then use the proceeds to purchase a new computer.
-
Please, need help with a query
Hi !
Please need help with this query:
Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
order by a.create_dateTake a look on the syntax :
max(...) keep (dense_rank last order by ...)
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#i1000901
Nicolas. -
Please need help with this query
Hi !
Please need help with this query:
Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
order by a.create_datePerhaps something like this...
select id, create_date, loanid, rate, pays, gracetime, emailtosend, first_name, last_name, user_id
from (
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id,
max(create_date) over (partition by a.user_id, a.loadid) as max_create_date
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
where create_date = max_create_date
order by create_date -
I need help with SQL query (if it can be accomplished with query at all).
I'm going to create a table with structure similar to:
Article_Name varchar2(30), Author_Name varchar2(30), Position varchar2(2). Position field is basicly position of an article author in the author list, e.g. if there is one author, his/her position is 0, if 2, then 1st author is 0, second is 1, etc.
Article_Name Author_Name Position
Outer Space Smith 0
Outer Space Blake 1
How can I automate creation of Position, based on number of authors on the fly? Let's say I have original table without Position, but I want to create a new table that will have this information.
RegardsIf you have an existing table whose structure doesn't tell you what position the author is in, what's the algorithm you'd use to determine who was the first author, the second author, etc? If you issue a select query on a table without providing an "order by" clause, Oracle makes no guarantees about the order in which it retrieves rows.
As an aside, why would you store position number in a varchar2 field? If it's a number, it ought to be stored as a number.
Justin -
Hi guys can someone help with a query regarding the 'podcast app' why do they not have all the episodes that relate to one show available why only half or a selected amount
THanks...but some days they have all the episodes right back to the very first show...ive downloaded a few but they are only available every now and then which makes no sense...why not have them available the whole time ??
-
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Need urgent help with the query - Beginer
Hello - I need help with a query to populate data in a table.Here is the scenario.
Source1
MnthID BranchCod CustID SegCode FXStatus ProfStatus Profit
200712 B1 C1 20 Y Y 100
Source2
MnthID BranchCod CustID ProdCode ProdIndex
200712 B1 C1 12 1
200712 B1 C2 12 0
Destination
MnthID BranchCod SegCode ProdCode CountSegCust CountProdCust ProfitProdCust
Condition and Calculations:
1)Source1 customer are base customers.If Source2 has customers who is not in source1 then that customer's record should not be fetched.
2)SegCode, FX Status, ProfStatus is one variable in destination table. [ SegCode = SegCode+ FXStatus (if FXStatus = Y)+ ProfStatus (if FXStatus = Y) ]
3)CountSegCust = CountCustID Groupby MnthID,BranchCod,SegCode Only.
4)CountProdCust = CountCustID Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
5)ProfitProdCust = Sum of Profit of Customers Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
Apologies for bad formatting.
Thanks in advance!!A total guess indeed.
It's not clear whether some aggregation can be done (summing counts of grouped data might cause some customers being counted more than once)
insert into destination
select mnthid,branchcod,segcode,prodcode,countsegcust,countprodcust,profitprodcust
from (select s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end segcode,
s2.prodcode,
count(s1.custid) over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
order by null
) countsegcust,
count(case proindex when 1
then custid
end
) over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
s2.prodcode
order by null
) countprodcust,
sum(case proindex when 1
then profit
end
) over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
s2.prodcode
order by null
) profitprodcust,
row_number() over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
s2.prodcode
order by null
) the_row
from source1 s1,source2 s2
where s1.mnthid = s2.mnthid
and s1.branchcod = s2.branchcod
and s1.custid = s2.custid
where the_row = 1Regards
Etbin -
I created a blogging tool for my students to use as I teach
them internet safety and cyber citizenship. I am no CF master, but
I dabble a little bit here and there. I need some help with this
query. It is running extremely slow, which means I have probably
created some horrendous loop in this query. If any one out there
has a better solution for this query, I and my middle school
students would be extremely grateful.
Here's what I would like it to do. I have two tables, one for
the blog messages and another for comments. The comments are linked
to their respective blog messages through a common database field.
When someone clicks on a link to read a student's blog, a query
runs which pulls all of the blog messages for that user, the
comments, and it also counts the number of comments entries for
each message so that I can place a total # of comments under each
blog message.Not sure why you have this like this: (Select
count(commentid) from comments where comments.blogid = blog.blogid)
or this twice: blog.blogusersid = #fname#
You need to make sure that the comments.blogid and
blog.blogid fields are indexed. Does this query work any faster?
<cfquery Name="Myblog" datasource="blog">
SELECT b.blogid, b.btitle, b.bcontent, b.bdate,
b.blogusersid, b.fname, b.lname, b.blogpict, b.pictlocation,
b.userid, c.commentid, c.blogid, b.lastupdated, COUNT(c.commentid)
AS cc
FROM blog AS b
INNER JOIN comments AS c ON c.blogid = b.blogid
WHERE b.blogusersid = #fname#
GROUP BY b.blogid, b.btitle, b.bcontent, b.bdate,
b.blogusersid, b.fname, b.lname, b.blogpict, b.pictlocation,
b.userid, c.commentid, c.blogid, b.lastupdated
ORDER BY b.bdate
</cfquery>
..... but I'm not sure that you will be getting the comment
count that you want with either query.
Phil -
Help with access control please
So I'm trying to set up my brother's PSP to the wirless network through MAC address timed access. What I want to do is make it so that he can only access it through certain times in the day. I'm having troubles with actually getting it to work. Everytime I set it up, the PSP only show's up as a DHCP client and not a Wireless client. I tried the option panel with the add wireless clients through the first try access. Could I get some help with this issue please? Thanks!
Just to calm your fears... There is no conspiracy. If someone had an answer or a suggestion they would post it.
-
I keep pressing verify and it not working can you help me out , Thanks Please reply back .HELP!
Have you tried logging out of your account on the phone by tapping on your id in Settings > iTunes & App Stores and then logging back in and seeing if that 'refreshes' the account on it ?
If that doesn't work then you can contact iTunes support via this page (these are user-to-user forums, you are not talking to Apple here) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page -
select * from testme;
NAME VAL
A 1
A 2
A 3
B 1
B 2
B 3
C 1
C 2
I want to get the maximum of name and the maximum of corresponding name's value.
ie., the answer should be
Name VAL
C 2
Please help me with the query.
ThnxSQL> create table testme
2 as
3 select 'A' name, 1 val from dual union all
4 select 'A', 2 from dual union all
5 select 'A', 3 from dual union all
6 select 'B', 1 from dual union all
7 select 'B', 2 from dual union all
8 select 'B', 3 from dual union all
9 select 'C', 1 from dual union all
10 select 'C', 2 from dual
11 /
Tabel is aangemaakt.
SQL> select max(name) name
2 , max(val) keep (dense_rank last order by name) val
3 from testme
4 /
NAME VAL
C 2Regards,
Rob.
Maybe you are looking for
-
OBIEE report filter and delivery ibots
Hi All, One of my reports (with 20 cols) consists of multiple rows with repeated customer names (about 100 distinct customer names and approx total 5000 rows). We wanted to automatically filter out the report on customer names and send the filtered r
-
Hello, I worked with SQL 7 and SQL 2000 many years ago (I also worked some with Oracle). About 14 years ago I got involved with AIX and then SAN administration. I've been completely disconnected with SQL Server and Microsoft technologies during that
-
I can't view my photos on my TV using AppleTV. This is because when I get to the iCloud Photo Settings page and turn on My Photo Stream,there seems nowhere else to go to look at my photos. I guess there is a simple answer! Can anyone help.....please
-
Aperture and iPhoto library deleted
I upgraded my Aperture w/no problem. About one month later, all images in Aperture and iPhoto dissapeared. "Genius Bar" checked, said no problem and didn't have a clue. Bought a Time-Machine backup at store, had a consultant there show me how to set
-
I am trying to find a way to access the instance of a Resource in an AuthorizationProvider in order to be able to determine if a specific user can access one instance of that resource. Example, my Resource is an EntityBean named: TestEntityBean, the