Finding a total in a query
Hi People.
If it's one thing that gets me every time is pulling a total of inputs from a table for a common entry. The query below is pulling a list of logged hours for a production order (or an addon to SAP B1 called a process order).
I want to have a single line with the production order number, with the total of planned hours per labour task with a total of the actual hours recorded for that production order. I've stripped this query back to the basics and placed it as best I know but I'm still getting multiple lines per production order.
Any help would be great.
SELECT distinct t0.PrOrder, sum(t1.Quantity) [PlannedQty2], sum(t2.[total quantity]) [ActualQty2]
FROM IIS_EPC_PRO_ORDERH t0
left JOIN (select distinct t1.prorder, sum (t1.quantity) [Quantity] from IIS_EPC_PRO_ORDERL t1 group by t1.prorder, t1.quantity) as t1 ON t0.PrOrder = t1.PrOrder
left JOIN (select distinct t2.prorder, sum(t2.quantity) [total quantity] from IIS_EPC_PRO_ORDERT t2 group by t2.prorder, t2.quantity) as t2 ON t0.PrOrder=t2.PrOrder
WHERE t0.sonum > '0'
GROUP BY t0.PrOrder, t1.Quantity, t2.[total quantity]
Hi Try this,
I just removed quantity field in group by
SELECT distinct t0.PrOrder, sum(t1.Quantity) [PlannedQty2], sum(t2.[total quantity]) [ActualQty2]
FROM IIS_EPC_PRO_ORDERH t0
left JOIN (select distinct t1.prorder, sum (t1.quantity) [Quantity] from IIS_EPC_PRO_ORDERL t1 group by t1.prorder, t1.quantity) as t1 ON t0.PrOrder = t1.PrOrder
left JOIN (select distinct t2.prorder, sum(t2.quantity) [total quantity] from IIS_EPC_PRO_ORDERT t2 group by t2.prorder, t2.quantity) as t2 ON t0.PrOrder=t2.PrOrder
WHERE t0.sonum > '0'
GROUP BY t0.PrOrder
Similar Messages
-
30,60,90 Days Totals in sql query
Hi All,
Here I have written a query to find the total for 30Days to calculate costs....
These 30Days Amount will be populated into another table based on joins.
I know we can do by case in the final update but lot of logic is going into temptables1 and 2, so please help...
select distinct ip.membernbr,ip.patcom,ip.admitdate,ip.dischargerdate,dateadd(day,1,ip.dishargedate) as afterdishcargedatestart,
dateadd(day,30,ip.dishargedate) as afterdishcargedateend, cd.specificdateofservice as ipdos, cd.specificdateofservicethry
as ipdosthru
into #inpatientdoshospice30
from tbl_inpatient ip
join claimsdetail cd on cd.membernbr=ip.membernbr
join claims c on c.claimsseqnbr=cd.claimnsseqnbr
where c.formnbr='inp'
and cd.specificdateofservice between dateadd(day,1,ip.dishargedate)
and dateadd(day,30,ip.dishargedate)
and cd.specificdateofservicethru
between dateadd(day,1,ip.dishargedate) and dateadd(day,30,ip.dishargedate)
--find part c hospice claims lines that that are already included in the inpatientcost(c.formnbr='INP')
cost;
--doing this in a separate step in case there are multiple inpatient claims which dos dates that overlap
(e.g; 1/15 to 1/20 and ---1/18 to 1/20) causing us to overstate dollars
select distinct ip.patcom,cd.claimssequencenbr
into #Hospiceinpatientclaimnslines30
from
#inpatientdoshospice30 ip
join claimsdetail cd on cd.membernbr=ip.membernbr
and cd.specificdateofservice between dateadd(day,1,ip.dishargedate) and dateadd(day,30,ip.dishargedate)
and cd.specificdateofservicethru between dateadd(day,1,ip.dishargedate) and dateadd(day,30,ip.dishargedate)
join claims c on c.claimsseqnbr=cd.claimnsseqnbr
where c.formnbr='Hospice'
--sum all hospice claims excluding those already included in the inpatient
update pp
set homehospicecost30day=isnull(sub.hospicecost,0)
from inpatient pp
left join(
select ip.patcom,sum(isnull(cd.netamt,0.00)) as hospicecost
from tbl_inpatient ip
join claimsdetail cd on cd.membernbr=ip.membernbr
and cd.specificdateofservice between dateadd(day,1,ip.dishargedate) and dateadd(day,30,ip.dishargedate)
and cd.specificdateofservicethru between dateadd(day,1,ip.dishargedate) and dateadd(day,30,ip.dishargedate)
join claims c on c.claimsseqnbr=cd.claimnsseqnbr
where (c.formnbr='Hospice' or (c.formnbr='PartB' and cd.placeofservice in ('34')))
and cd.claimsseqnbr not in (select cklaimseqnbr from #hospiceinpatientclaimlines30 sub where sub.patcom=ip.patcom)
group by ip.patcom
)sub
on pp.patcom=sub.patcom
I really appreciate your help.
Thanks,
Kalyan.The UPDATE can be written this way:
update pp
set homehospicecost30day = isnull(sub.hospicecost,0)
from inpatient pp
left join(select ip.patcom,
sum(CASE WHEN cd.specificdateofservice between
dateadd(day,1,ip.dishargedate) AND
dateadd(day,30,ip.dishargedate)
AND cd.specificdateofservicethru between
dateadd(day,1,ip.dishargedate) and
dateadd(day,30,ip.dishargedate)
THEN isnull(cd.netamt,0.00)
ELSE 0
END) as hospicecost30
from tbl_inpatient ip
join claimsdetail cd on cd.membernbr=ip.membernbr
join claims c on c.claimsseqnbr=cd.claimnsseqnbr
where (c.formnbr='Hospice' or
(c.formnbr='PartB' and cd.placeofservice in ('34')))
and cd.claimsseqnbr not in (select cklaimseqnbr from
#hospiceinpatientclaimlines30 sub
where sub.patcom=ip.patcom)
group by ip.patcom)sub
on pp.patcom=sub.patcom
The pattern shows how you can add further days.
I was not able to figure out the meaning of the temp tables, and since you said that you typed it from memory without access to the code, I don't trust that you got everything right. Give it a second look on Monday.
Erland Sommarskog, SQL Server MVP, [email protected] -
Hi Gurus,
I need to find out what is the total run time of a query in production. I browsed RSDDSTAT table in se11 but I don't know what is the name of the column to find out total run time. Is it qruntimecategory ? Please advice .
Thanks
LizaHi Liza,
Goto ST03N transaction and select the expert mode and under BW system load you can check for the query you want. Here it gives the detailed view of the query. But to do this, the statistics for the cubes should have been enabled. for that, goto RSA1, tools-> BW statistics for the infoprovider and select your infoprovider and save. then run the query and you will see the result in ST03N.
Sriram -
How to find the cpu usage per query for a time period
Hi All,
Is there a way to find the cpu used per query for a given time period?
DB:10.2.0.5
OS:AIX
Thanksuser13364377 wrote:
if there are multiple queries starting at the same time, then what to do?Handle: user13364377
Status Level: Newbie (10)
Registered: Jul 5, 2010
Total Posts: 264
Total Questions: 113 (84 unresolved)
why so many unanswered questions?
clarify your question
same SQL multiple times from different sessions?
or
different SQLs from different sessions? -
Difference between 2 sub-totals in SAP query
Hello Experts,
Is there any possibility to find out the difference between 2 sub-totals and display it at the bottom of the ALV output( like total) in SAP Query using SQ01.
For example: see below example(Request you to paste the below in an excel sheet for more readability).
PRZ 25.05.2011 A 007 008 01 15 10 EA 0,00 INR 0,00 INR 2,00 INR 0,00 INR
PRZ 27.05.2011 A 007 008 01 00 1 PC 10,00 INR 0,00 INR 0,20 INR 0,10 INR
PRZ 27.05.2011 A 007 008 01 00 1 PC 10,00 INR 0,00 INR 0,20 INR 0,10 INR
Sub-total 10 EA 20,00 INR 0,00 INR 2,40 INR 20 INR
2 PC
DRP 26.05.2011 WDB2020261X744924 1 PC 60,00 INR 50,00 INR 30,00 INR 0,00 INR
DRP 31.05.2011 WDB2020261X744924 1 PC 60,00 INR 50,00 INR 30,00 INR 0,00 INR
Sub-total 2 PC 120,00 INR 100,00 INR 60,00 INR 0,00 INR
Grand totals 10 EA 140,00 INR 100,00 INR 62,40 INR 20 INR
4 PC
In the same way as Grand total, Is there any possibility to find out the difference between the 2 sub-totals and display at the bottom after the Grand Totals row.
Please let me know if there is any possibility for the same.Just to update on my question.
In the sub-totals line you can see that there is 20,00 INR value which is summation of the above fields present in individual line numbers above. And the same way for the rest of the fields as well.
After calculating the sub-totals in this manned, I need to find out the difference between the subtotals and display it at the bottom of the output.
Please let me know if this is possible. -
How do I find the total size of all my Music in iTunes 11?
I'm looking to get a new iPod, either a nano or Touch, so I'm trying to find the total size of all of my Music. Since iTunes 11's interface is so different from previous versions, I don't see a way to view that.
Ctrl B to show top menu
View Show Status Bar to show the grey bar at the bottom with the info you want.
While your there View> Show Sidebar and see if you prefer that. -
How do i find the total number of fields within all tables in one of my databases
I'm in the process of creating some "gee whiz" metrics for one of my applications and want to find the total number of columns contained in its database. Is there a stored procedure to get this information that would save me the effort
of opening each of my 66 tables and counting the columns? I also have the same question for my 138 views. Thank you for any ideas you care to offer...............Phil Hoop
Phil HoopHi Phil,
Assumes SQL 2005 or higher
Let 's try simple one ....
SELECT COUNT(col.column_name), col.table_name
FROM information_schema.columns col
JOIN information_schema.tables tbl
ON tbl.table_name = col.table_name
AND tbl.table_schema = col.table_schema
AND tbl.table_catalog = col.table_catalog
AND tbl.table_type = 'VIEW'
GROUP BY col.table_name
Let me know if this will help you.
If you think my suggestion is useful, please rate it as helpful.
If it has helped you to resolve the problem, please Mark it as Answer.
Varinder Sandhu www.varindersandhu.in -
How to find out total of number of users accessing Hyperion Planning applications ?
Hi All,
Could someone help me with the details of how to find out total number of users who are accessing Hyperion Planning application in Env.?
This is with regard to licenses so wanted accurate and unique information,
Thanks
AmithHello Amith,
I think you should have a look at the blog of Cameron Lackpour http://camerons-blog-for-essbase-hackers.blogspot.be/
In the "Shared Services Stupid Trick" blogs, he shows how to find the real access to an application. The side benefit is that it is amusing to read.
In how far this is OK for the licenses is written on another page. You likely need to use the same method as Oracle does. Ask the Salesperson how to do this. (I am curious what his/her reply is).
Regards,
Philip Hulsebosch. -
How can i find out total no of sunday in the year
Hi Experts,
how can i find out total no of sunday's in the particular year. please can any one help how can i do that
Regards,
ArunJust for fun (and in case this wasn't done to death in the other thread), the rule posted here states:
Most years have 365 days, but a leap year has 366 days. That adds up to 52 weeks (where each week is exactly 7 days) PLUS 1 or 2 additional days. The year 2012 has exactly 366 days.Now if the year starts on a Sunday in a non-leap year, you end up with 53 Sundays. Or if either of the first two days lands on a Sunday during a leap year, then you can also get 53 Sundays.>
which allows a calculation like this:
with test_data as
( select rownum + 1999 as test_year from dual
connect by rownum <= 15 )
select test_year
, case
when first_day = 'SUN'
or ( first_day = 'SAT' and leap_year = 'Y' )
then 53
else 52
end as sundays
from ( select test_year
, to_char(to_date(d.test_year||'-01-01','YYYY-MM-DD'),'DY', 'NLS_DATE_LANGUAGE=ENGLISH') first_day
, case extract(day from last_day(to_date(d.test_year||'-02','YYYY-MM'))) when 29 then 'Y' else 'N' end as leap_year
from test_data d );
TEST_YEAR SUNDAYS
2000 53
2001 52
2002 52
2003 52
2004 52
2005 52
2006 53
2007 52
2008 52
2009 52
2010 52
2011 52
2012 53
2013 52
2014 52
15 rows selected. -
Unable to find the universes in the Query Browser Panel of Dashboard Design
Hi Experts,
Can any one please help me out, as I am Unable to find the universes in the Query Browser Panel of Dashboard Design Tool.
Thanks & Regards,
Shivani
Edited by: Shivani Yemula on Jul 19, 2011 4:40 PMHi,
I got the same problem recently in BI 4.1 Platform and all the permissions were already set, I mean on the universe and all others which are required but I found there was some problem in Dashboard Cache server, when I restarted that it worked fine ...
I was able to see the universe once I restarted it. I was getting a Java unable to invoke object Error..
Thanks,
Vamshi -
How to find Tables behind a Custom Query in SAP
Hi Gurus,
Can anyone please help me find tables behind a custom query in SAP.
Regards
AsHi
Check the name of the programm assigned to transaction, it should be like this:
AQZZ<user group>=======<query name>======
or
AQIC<user group>=======<query name>======
It depends of the query area is global or cross-client
So run SQ01, select the quey area, select the quey group and so your query: now you can see the infoset and then you see it by SQ02 transaction
Max -
How to find who has deleted the query in Production system
I Experts,
I have an issue. Someone has deleted one query in Production system.
How can i find who has deleted the query??
I searched the ans for the same i the below threads :-
Query deleted in production
How to find out who has deleted the production Query
But it didn't help me as i couldn't understand how to use the transaction SLG1.. Can Someone please explain me how can i find out who has deleted the Query..
Regards,
Pavan RajHello,
Please, remember the date on which date the query has seen last time in the production server. You can use the last date in the From date and To date would be current date and execute the SLG1 tcode. It would list you all the logs in the Object text you can search for BEX Query designer and sub object text column you can check for delete logs options.
Double click on the object will list you the query and name. From the user column you can find who has deleted the query.
Might be this can help you for analysis.
Thanks
Geeta Sharma -
Finding The statistics of a Query
I would like to find the statistics of a query.
we can obtain the stats when we do "set autotrace on" in SQL PLUS.
and when we run a query it gives the reads, recursive calls etc.
where are these stats stored? where can i get them from?
to add more to it;
we can select the Plan from of a query after explaining the plan and running this query - select * from table(DBMS_XPLAN.display);
Is there a similar way to select the statistics of the query?
Thanks.can you please explain what does the staistic refer to?Have a look at Statistics Descriptions
-
When I run the code below I get the following error:"RUN-TIME ERROR '3078': The Microsoft Access database engine cannot find the input table or query 'False'. Make sure it exists and that its name is spelled correctly. Note that I do not call
anything by the name of "false" anywhere in this code.
The subject code (the underscored line of code is highlighted in the debugger when the error occurs):
Option Compare Database
Private Sub JobAssign_Click()
MatLotListAvail_openform
End Sub
Function MatLotListAvail_openform()
Dim dbsAPIShopManager2010 As DAO.Database
Dim rstMaterialLotJobJoint As DAO.Recordset
Dim strSQL As String
Set dbsAPIShopManager2010 = CurrentDb
strSQL = "SELECT * FROM MaterialLotJobJoint WHERE JobID" = "tempvars!JobID" And "MatLotID" = "tempvars!MatLotID"
Set rstMaterialLotJobJoint = dbsAPIShopManager2010.OpenRecordset(strSQL, dbOpenDynaset)
If rstMaterialLotJobJoint.EOF Then
DoCmd.OpenForm "JobAssignMatConf", acNormal, "", "", acEdit, acNormal
Forms!JobAssignMatConf!PartapiIDVH = TempVars!PartapiID
Forms!JobAssignMatConf!JobapiIDVH = TempVars!JobapiID
Forms!JobAssignMatConf!JobIDVH = TempVars!JobID
Forms!JobAssignMatConf!MaterialLotIDVH = TempVars!MatLotID
Forms!JobAssignMatConf!Desc = TempVars!MatDesc
Forms!JobAssignMatConf!recdate = TempVars!recdate
DoCmd.Close acForm, "MaterialLotListAvailable"
Else: MsgBox "This material lot has already been assigned to this job."
DoCmd.Close acForm, "MaterialLotListAvailable"
End If
End FunctionI think the SQL statement should be
strSQL = "SELECT * FROM MaterialLotJobJoint WHERE JobID=" & _
tempvars!JobID & " AND MatLotID=" & tempvars!MatLotID
This assumes thatJobID and MatLotID are number fields.
Regards, Hans Vogelaar (http://www.eileenslounge.com) -
How do I find the total number of elements in a multi dim array
How do I find the total number of elements in a single or multi dim array?
For example, a 2x3 array has 6 elements, and a 2x3x4 has 24. How do I compute this very easily - is there a single VI that does this?
David
Solved!
Go to Solution.Use "array size" (array palette) followed by "multiply array elements" (numeric palette)
(Works also equally well for 3D arrays and higher)
For a 1D array, just use "array size".
Message Edited by altenbach on 02-05-2009 05:57 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
NumberOfElements.png 3 KB
Maybe you are looking for
-
Hi. So I am trying to help a friend with her laptop. It's a HP Pavilion g6-2330dx. Product #: D1C01UA#ABA Serial #: [Personal Information Removed] Windows 8 ADATA 4GB RAM Toshiba 640GB HDD from the looks of it. The laptop is unable to boot into Windo
-
Error message in Adobe 9.1.2
I recently had some e-magazines sent to me but when I try to open them I get an error message that Adobe Reader encountered a problem and had to shut down.This happen at thye parties web site as well. Any ideas? Bob
-
Hi Gurus, I want to print the cheque by giving payee name against the expense posted. By using RVND transaction, voucher is posted but cheque is not coming out, please tell me how can i solve this issue. Thank You
-
Networking two NI lookout servers with different windows OS
Can I networking two NI lookout servers with 50 I/O, one with windows98 SE and one with Withows XP pro.?
-
I can't change the "media kind" to book from music because this option is greyed out. How can I change this so I can view the digital booklet that should have come with my "delux" purchase?