Count when ID number sum total 300
Afternoon Folks,
Just wondering if somebody could help me with a code query?
I'm trying to count the number of Service Packs where the sum payment total for each distinct sp_id is less than £300 and also greater than £300.
This is the code I have so far:
select specialty,
count(distinct sp_id) "Service Packs",
sum(payment_total) "Total Paid £",
round(sum(payment_total)/count(distinct sp_id),0) "Average Spend per SP"
from a3_fact_sms_service_inv
where specialty in ('Chiropody','Podiatry')
and service_date between '01Jan11' and '31Dec11'
group by specialty
This is the table of what I want it to look like
SPECIALTY Service Packs Total Paid £ Average Spend per SP *<300* *>300*
Chiropody 129 25682.26 199 *107* *22*
Podiatry 622 206651.08 332 *403* *219*
I'm currently running 10g application
Regards
Wardie:)
Hi,
when you post some code please include them between {noformat}{noformat}.
i.e.:
{noformat}{noformat}
DECLARE
a
{noformat}{noformat}
Additionally provide some table creation, sample data and expected output.
Please read [url:SQL and PL/SQL FAQ do I ask a question on the forums?[/url].
*Removed my suggestions as I misunderstood the problem*
Regards.
Al
Edited by: Alberto Faenza on Oct 24, 2012 5:05 PM
Updated
Similar Messages
-
Count by id not by total number of amount paid
hi i what to count by total id not by total number of amount paid
{SELECT COUNT(*)NoEcd,agr.SSCH_ID,SUM(amount)FROM SMS_AGREEMENTS agr,
SMS_AGREEMENT_YEARS yea,
SMS_PAYMENTS PAY
WHERE agr.id = YEA.agr_id
AND agr.ssch_id IN(1,3,24)
AND PAY.AYEA_ID = yea.ID
AND yea.FYEA_YEAR IN( 2008)
GROUP BY agr.SSCH_ID }
NOECD | SSCH_ID| SUM(AMOUNT)
*627* | 1 | 5186229
*10181* | 3 | 114057485
*336* | 24 | 1120882
this is the number of id without total amount paid when i put total amount paid the total id change
{SELECT COUNT(agr.SSCH_ID)NoEcd,agr.SSCH_ID FROM SMS_AGREEMENTS agr,
SMS_AGREEMENT_YEARS yea
-- SMS_PAYMENTS PAY
WHERE agr.id = YEA.agr_id
AND agr.ssch_id IN(1,3,24)
--AND PAY.AYEA_ID = yea.ID
AND yea.FYEA_YEAR = 2008
GROUP BY agr.SSCH_ID;}
i what this with the total amount paid like top
NOECD| SSCH_ID
*63* | 1
*868* | 3
*35* | 24
Edited by: user603350 on 2011/07/11 11:59 PM
Edited by: user603350 on 2011/07/12 1:29 AM
Edited by: user603350 on 2011/07/12 1:58 AM
Edited by: user603350 on 2011/07/12 2:00 AM
Edited by: user603350 on 2011/07/12 2:21 AM
Edited by: user603350 on 2011/07/12 2:24 AM
Edited by: user603350 on 2011/07/12 2:25 AMhi i what to count by total id not by total number of amount paid
i try to edited, i only what to count by id like in the last query,the last query muts have total piad like first query but with the total ecd in bold in last query
{SELECT COUNT(*)NoEcd,agr.SSCH_ID,SUM(amount)FROM SMS_AGREEMENTS agr,
SMS_AGREEMENT_YEARS yea,
SMS_PAYMENTS PAY
WHERE agr.id = YEA.agr_id
AND agr.ssch_id IN(1,3,24)
AND PAY.AYEA_ID = yea.ID
AND yea.FYEA_YEAR IN( 2008)
GROUP BY agr.SSCH_ID }
NOECD SSCH_ID SUM(AMOUNT)
*627* 1 5186229
*10181* 3 114057485
*336* 24 1120882
this is the number of id without total amount paid when i put total amount paid the total id change
{SELECT COUNT(agr.SSCH_ID)NoEcd,agr.SSCH_ID FROM SMS_AGREEMENTS agr,
SMS_AGREEMENT_YEARS yea
-- SMS_PAYMENTS PAY
WHERE agr.id = YEA.agr_id
AND agr.ssch_id IN(1,3,24)
--AND PAY.AYEA_ID = yea.ID
AND yea.FYEA_YEAR = 2008
GROUP BY agr.SSCH_ID;}
i what this with the total amount paid like top
NOECD SSCH_ID
*63* 1
*868* 3
*35* 24 -
Any advice on count when sum 0
Hi there
We would like to have 1 sql such that
count when sum of value in column > 0 . Problem is sum an aggregate function and also count.
As example imagine 2 customer records, one has a -ve value e.g -4 and 1 a positive value of +5 so sum of these values = +1. Such a customer we would like to include in the count and can't simply use having clause as we wish to include in report all sales reagrdless of whether > 0 but a separate count field to highlight the ones which are greater than 0
Current sql
select sum(value), cola..
from table
group by col1..
can't say
select count(case when sum(value) > 0 then distinct cust_id end)
as get ora-message about nested group by functions..
Anybody done such a thing before - would analytical functions work in this situation.
Many ThanksHi there,
Thanks very much for the replies.
One problem though, unfortunately the reporting tool we use is quite constrained and we can't implement the solutions proposed in it - they would have been preferable.
Example of data
table called transaction with all different types of transactions
Main fields, trans-code, cust_id, product_id, trans_qty, trans_date
Each row has a different trans code, e.g supply code, return code.
We wish to identify no of custs sold out. A customer could have several supply transaction records for the same product and potentially several different return transactions.
If the sum of all the supply transactions for a customer/product > 0 and the sum of all the credit transactions for a customer/product = 0 then we count this as a sell-out.
Is it possible to code this as an analytical function - if so how?
Many Thanks -
I am having a problem with adding selected numbers in a column. When I select "sum" the whole column is added, not just the selected cells. I would appreciate any help how to rectify? Many thanks. Francis Anthony
I don't know if this is the best way but it's pretty easy.
1.) Select the cell you want the sum in.
2.) Select the sum function
3.) In the line where you see =sum(B2:B8) using your finger tap the B2:B8
4.) Use the backspace key to delete the B2:B8 and it will then show "value"
5.) You can now tap any cell you want in the sum
6.) When finished tap the green check mark button at the end of the sum line.
That pretty much sums it up.
Good luck.
Steve -
Display Sum Total Of Listview Items
Can anyone help me with displaying Sum Total of Listview Items in a label. I tried this:
Dim dblTotal as Double = 0
Dim dblTemp As Double
For Each lvItem As ListViewItem In lvwTemps.Items
If Double.TryParse(lvItem.SubItems(2).Text, dblTemp) Then
dblTotal += dblTemp
End If
Next
Label2.Text = dblTotal
but it's just giving me 0 in the labelHi
Seems like you might have a second VB Editor open? In any case, save the Project, close down VB and rerun will probably fix it.
Regards Les, Livingston, Scotland
Yes, that worked but it gives me an unreal number ..
You'll need to take the unit into consideration and convert all values to the same unit, for example, MB:
Dim dblTotal As Double = 0
Dim dblTemp As Double
For Each lvItem As ListViewItem In lvwTemps.Items
Dim values() As String = lvItem.SubItems(2).Text.Split(" "c)
If Double.TryParse(values(0), dblTemp) Then
If values(1) = "MB" Then
dblTemp *= 1000000
ElseIf values(1) = "KB" Then
dblTemp *= 1000
End If
dblTotal += (dblTemp / 1000000)
End If
Next
Label2.Text = dblTotal
Reed Kimble - "When you do things right, people won't be sure you've done anything at all" -
Need a formula to calulate multiple cells and add the sum total to a cell in a other table
Im a chef and my monthly inventory is a time consuming task. I get invoices from multiple suppliers on each day of the week. I enter them into a spread sheet and then need to add the sum total for all the invoices for say MONDAY. That total needs to be entered into a cell in another table called "daily spend". Is there a formula to automatically add say all the invoices from monday and input the daily spend cell on that table. Here is an example
I created a column B-to give each day a number(sometimes multiple invoices come from the same supplier for each day)<GREEN>..If there was a way to do this differently...Im happy to change the layout of the spreadsheet. I want to add the total $ (column F) for each day together(all the blue fields) and then insert the total into another cell seen in the next table . So in this example its F4+F16+F17=?, ? inserted into N2 of the next table
Thanks so much"I ve finally has a play with the advice you gave me but I have realized that the formula you gave me is for a week....and like I mentioned in my reply to you, one table is weekly the other is monthly....is there a way to overcome this? (my answer to you explains it)"
Hi Gavin,
Unfortunately, the scale of your illustrations in that reply made them difficult (or impossible) to read, even on the Retina screen.
The first formula, used to fill column B, extracts the Weekday number for each date. Since these numbers should be equivalent to the day of the month, You'll need to replace this with a formula that returns the Day value of each date:
Old:
B2: =WEEKDAY(A,2)
New:
B2: =DAY(A)
Fill down to end of column.
Because of the arrangeent of your Data table, you will need to repeat this formula in column H (with references to column G), etc. for each set of dates in the table.
The SUMIF formula in column F is fine as is, except that it assumes all condition data will be in column B of Data, and all data to be summed will be in column F of Data. Since this is obviously not the case for your Data table, you will need a separate iteration of the formula for each week in the table, with the four SUMIF statements enclosed in a SUM statement:
E2: =SUM(SUMIF(Data :: $B,A2,Data :: $F),SUMIF(Data :: $H,A2,Data :: $L),SUMIF(Data :: $N,A2,Data :: $R),SUMIF(Data :: $T,A2,Data :: $X))
Fill down for as many rows as there are days in the month being summarized.
Column references in the formula assume that six columns are used for each week, and that there is no gap in the table between weeks.
Note that the formula does not distinguish between transactions on July 7 and those on June 7 or August 7. Because of this, the Data table must be limited to transactions in a single calendar month.
Regards,
Barry -
Uploading Linked Captivate 2 Projects into Sum Total LMS
I've been trying to upload a series of media-rich linked
projects to our Sum Total LMS. Although there are several projects,
they are linked to play seamlessly to the end user. The problem is
when each project is published, it creates its own zip file. In
order to upload the files to the LMS they must be in one zip file
or they will upload as separate, independent learning modules. I've
encountered numerous challenges in attempting the upload.
Does anyone have any experience/suggestions about:
- Publishing each project into the same zip file
- Uploading linked Captivate 2 projects to an LMS, especially
the Sum Total LMS
- Uploading a project with flash videos to an LMS
I greatly appreciate any feedback you can provide.
Thanks!I always link between Captivate files to ensure that my files
are not too big. I have done this many times; however, I have not
tried it when there is a quiz involved. What I do is link them
inside Captivate, publish the files (non-zipped, which you can do
if there isn't a quiz involved) and then zip them up together with
Winzip. When you load it into the LMS, you need to choose either
"Knowledge Document" or "General Document" and there, you can
choose the launch file (whatever file you want to load
first.) -
Total Score in Sum Total not correct
We are using Captivate 4 and the Sum Total LMS. Our course consists of 2 lessons which are not scored and an assessment which is scored. The settings for the lessons are Slide Views Only so the lessons have the Topic Status Complete or Incomplete on the Sum Total LMS Learning Activity Progress Detail page, with the Score % blank. The assessment also has Topic Status Complete or Incomplete, and also a Score % (80% required to pass). The Topic Status and Score % values are correct for the lessons and the assessment, however the Total Score is not correct. When the user completes the 2 lessons and the assessment with a score of 100%, the Total Score shows as only 33%. So it seems that Sum Total is including the lessons in the Total Score, and calculating the Total Score by (100+0=0)/3 = 33%, i.e. assigning 0% to the lessons even though the Score % is blank for the lessons.
Is there a way to have the Total Score be just for the assessment? If the user scores 100% on the assessment we would like the Total Score to be 100%.Hi,
Can you make your question more clear, it is not clear what is you requirement exactly.
'.Total stock not issued from gate in stock.' : Yuou mean to say GR made with 103 but 105 not done for that
or Total stock in store but not issued yet ) : there is no GI with any movemen type ??
regards,
zafar -
How To Get rid of Exponential format in datagridview when the number is very large
When the number is very large like :290754232, I got 2.907542E +08. in datagridview cell
I using vb.net , framework 2.0.
how can I get rid of this format?
Thanks in advanceshould I change the type of this column to integer or long ?
The datagridview is binded to binding source and a list ( Of).
Mike,
I'll show you an example that shows the correct way to do this and a another way if you're stuck using strings in exponential format. The latter being the "hack way" I spoke about Friday. I don't like it, it's dangerous, but I'll show both anyway.
In this example, I'm using Int64 because I don't know the range of yours. If your never exceeds Int32 then use that one instead.
First, I have a DataGridView with three columns. I've populated the data just by creating longs starting with the maximum value in reverse order for 100 rows:
The way that I created the data is itself not a great way (there's no encapsulation), but for this example "it'll do".
Notice though that the third column (right-most column) isn't formatted at all. I commented out the part that does that so that I could then explain what I'm doing. If it works, it should look like the first column.
The first column represents an actual Int64 and when I show the code, you can see how I'm formatting that using the DGV's DefaultCellStyle.Format property. That's how it SHOULD be done.
The third column though is just a string and because that string contains a letter in it, Long.TryParse will NOT work. This is where the "hack" part comes in - and it's dangerous, but if you have no other option then ...
You can see that now the third column matches the first column. Now the code:
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
With DataGridView1
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToOrderColumns = False
.AllowUserToResizeRows = False
.AlternatingRowsDefaultCellStyle.BackColor = Color.Aquamarine
.ReadOnly = True
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.RowHeadersVisible = False
.RowTemplate.Height = 30
.EnableHeadersVisualStyles = False
With .ColumnHeadersDefaultCellStyle
.Font = New Font("Tahoma", 9, FontStyle.Bold)
.BackColor = Color.LightGreen
.WrapMode = DataGridViewTriState.True
.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
.ColumnHeadersHeight = 50
.DataSource = Nothing
.Enabled = False
End With
CreateData()
End Sub
Private Sub CreateData()
Dim longList As New List(Of Long)
For l As Long = Long.MaxValue To 0 Step -1
longList.Add(l)
If longList.Count = 100 Then
Exit For
End If
Next
Dim stringList As New List(Of String)
For Each l As Long In longList
stringList.Add(l.ToString("e18"))
Next
Dim dt As New DataTable
Dim column As New DataColumn
With column
.DataType = System.Type.GetType("System.Int64")
.ColumnName = "Actual Long Value (Shown Formated)"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "String Equivalent"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Formated String Equivalent"
dt.Columns.Add(column)
End With
Dim row As DataRow
For i As Integer = 0 To longList.Count - 1
row = dt.NewRow
row("Actual Long Value (Shown Formated)") = longList(i)
row("String Equivalent") = stringList(i)
row("Formated String Equivalent") = stringList(i)
dt.Rows.Add(row)
Next
Dim bs As New BindingSource
bs.DataSource = dt
BindingNavigator1.BindingSource = bs
DataGridView1.DataSource = bs
With DataGridView1
With .Columns(0)
.DefaultCellStyle.Format = "n0"
.Width = 150
End With
.Columns(1).Width = 170
.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.Enabled = True
End With
End Sub
' The following is what I commented
' out for the first screenshot. ONLY
' do this if there is absolutely no
' other way though - the following
' casting operation is NOT ADVISABLE!
Private Sub DataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _
Handles DataGridView1.CellFormatting
If e.ColumnIndex = 2 AndAlso e.Value.ToString IsNot Nothing Then
' NOTE! The following is dangerous!
' I'm going to use coercion to force the
' string into a type long. TryParse will
' NOT work here. This can easily throw an
' exception if the string cannot be cast
' to a type long. I'm "depending on" the
' the string to cast. At the very least
' you might put this in a Try/Catch but
' that won't stop it from failing (if
' it doesn't work).
Dim actualValue As Long = CType(e.Value.ToString, Long)
Dim formattedValue As String = actualValue.ToString("n0")
e.Value = formattedValue
End If
End Sub
End Class
Like I said, only use that hack way if there's no other option!
I hope it helps. :)
Still lost in code, just at a little higher level. -
Count Distinct in Pivot table totals? OBIEE 11.1.1.5
Hi,
I have got a column that counts distinct customers per each month of the year and at the end of the analysis, it should show distinct customer count of the year as TOTAL. How can it be achieved? Is it possible to customize pivot table totals?
Example:
Month Customers
Jan 10
Feb 20 (10 new customers)
Mar 15 (5 new customers)
TOTAL: 25 (distinct values --> 10+10+5)Thanks in advance.Hi MK,
I tried it already and it does not work. It takes the distinct value of each month, which is month's count distinct and then it sums. So the total is 45 (10+20+15) not 25.
Thanks for you reply. -
Sum the Sum total values above
Post Author: John Patterson
CA Forum: Formula
I have created a report that contains a list of values (in a group) that come from a formlar that has Sum {} totals in it. All I want to do is sum that list into one value below, just like Excel would do!
Crystal won't allow me to sum the results of group sum totals higher up the report. I have been told that I need to create a conditional running total or a set a variable to store the values required.
Any ideas?
Many thanks
JohnPost Author: fusion
CA Forum: Formula
Definitely Jami,I found out that Running Total is an answer. I still need to find out how to get a percentage of the total using a running total. When you use a summary option then there is a option that allows you to have the filed as a % of the total of that filed. How can you do the same using running total. I am trying to work with formulas but no any luck so far.Your help is highly appreciated -
I have a bug in 4.1.41 with Sum Total at the right...
Each cell in my display is a simple calc like SUM(Hits). This is then Sum totaled as a Grand total at
the right. Everything works fine in this case.
Now if I replace my simple calc with a more complex calc into the same calculation: DECODE(SIGN(NVL(SUM(Hits),0)-NVL(SUM(DECODE(Category,'Audio',Hits,'TV and Music',Hits,0)),0)+NVL(SUM(DECODE(Page,'Digital Music',Hits,'Listen to Music',Hits,0)),0)),1,0,1)...the Grand total at the right works fine the first time...until I save the sheet and exit...and then get back into Discoverer.
When I get back into Discoverer...my Grand total at the right displays as all blanks. It simply refuses to display like it did the first time when I defined it. In order to get around this bug, I have to makeup a new simple calc, and then redefine it by putting my more complex definition into it.
This gets old and is tedious. Anybody know what is going on?I have a bug in 4.1.41 with Sum Total at the right...
Each cell in my display is a simple calc like SUM(Hits). This is then Sum totaled as a Grand total at
the right. Everything works fine in this case.
Now if I replace my simple calc with a more complex calc into the same calculation: DECODE(SIGN(NVL(SUM(Hits),0)-NVL(SUM(DECODE(Category,'Audio',Hits,'TV and Music',Hits,0)),0)+NVL(SUM(DECODE(Page,'Digital Music',Hits,'Listen to Music',Hits,0)),0)),1,0,1)...the Grand total at the right works fine the first time...until I save the sheet and exit...and then get back into Discoverer.
When I get back into Discoverer...my Grand total at the right displays as all blanks. It simply refuses to display like it did the first time when I defined it. In order to get around this bug, I have to makeup a new simple calc, and then redefine it by putting my more complex definition into it.
This gets old and is tedious. Anybody know what is going on? -
Is there a How To on column sum totals, break formatting, 4 tabular reports
Hi,
I haven't needed to do a grand totals for a column until now. I see that there is built in BREAK FORMATTING. I looked for a how to on it but found none.
Anyone have a good reference to explain basics? customizations?
Thanks, BillHi there,
If your column alignment is right the Sum will be right too in bold.
Break Formatting/Display this text when printing report sums
You can do [h4]Total of Something[h4] or use Style, for instance.
Same with “Display this text on report breaks using #SUM_COLUMN_HEADER# substitutions”. [h4] #SUM_COLUMN_HEADER# [h4] for instance.
I hope this would help.
Konstantin -
Publish Captivate 4 module for Sum total
Hello everyone. I have two training modules that are not scored. They are demonstrations, not simulations. I need to publish them so that they can be added to a customers Sum Total LMS. What settings should I use when publishing to LMS? And any tips or tricks I should know? I do not have access to the LMS. For our training, we host our own internal web pages.
ThanksHi,
Thanks for the tips. I read some of the suggested resources, and created a click box on the last slide with click box settings as:
On Success --> Execute Javascript --> javascript:window.close()
... and Reporting settings as:
Include in Quiz (checked)
Report answers (unchecked)
Points = 1
Add to Total (checked)
The LMS system accurately flags the course complete, but the click action does not close / exit the module. This is a SCORM 1.2 module.
Any ideas? Is it possible to test this in HTML outside the LMS system, or am I forced to test this in the LMS system?
Thanks,
Henry -
hi,
plz i want to make row counter or row number in alv report , how can i?
ex.
NO : Name : age
1 : ahm : 12
2 : a2 : 25
3 : a3 : 30
30
waiting answers
thanksTake an additional field in your ITAB as 'counter'
Make counter = counter + 1, before your APPEND ITAB statement.
But I think better options is in TOP-OF-PAGE, take a value of counter = '<no>'.
DESCRIBE TABLE it_final LINES t_cnt.
CONDENSE t_cnt.
wa_top-typ = 'S'.
wa_top-key = 'Total no.of Records: '.
wa_top-info = t_cnt.
APPEND wa_top TO it_top.
CLEAR wa_top.
Edited by: ashleshabhagatshelke on Aug 31, 2010 3:24 AM
Maybe you are looking for
-
Hello Friends, I am working on <b>pdf based print form (adobe form)</b> in GTS module. When the activity message gets executed, the form is called. I am getting two errors when the activity message is executed. 1) <b>Error in PDF document formatting
-
Lenovo S720 Language issue (Chinese to english)
recently one of my friend gifted me Lenovo S720 Smartphone from china, Now problem is it all core programs in chinese, even Lenovo store is also in chinese, i tried to change language but core language for lenovo services and lenovo store still in ch
-
How to build distribution package with Agilent VISA as primary
Hi everybody, I build a distribution package under LW 8.0 in a PC(Agilent VISA is primary), then I install the distribution package in another PC. But I found the distribution package install NI VISA as primary in another PC. So How could I make
-
Prompts for old user's password when DL or updating apps?
I have a used IPhone 3G. I had signed out of previous user's account and made my own. Everything was fine, DL apps and suddenly I went to update an app and when prompted for password it is old user's email!? I do not understand as I've gone into sett
-
SQLException Scrollable Resultsets
Using JDeveloper 3.1, Weblogic 5.1, Oracle 8i Successfully connecting to db and extracting data with vanilla prepared statements and resultsets. Not using Oracle proprietary classes. Using oracle's classes12.zip and the ide classpath shows my classpa