Sum/Count Question
Hi: I'm very new to Crystal Reports, and have a question that is probably pretty simple, but has me stumped and at a standstill...
I've built a report in Excel that determines the number of days between two date columns, then has a series of summary fields that count how many records have 1 day, how many have 2 days, ... 3 days, etc... I'm trying to build something similar in CR that will do the same thing, but I can't find it. I'm thinking it should have something to do with the Count (fld, condfld) function, but think I'm having trouble getting the syntax right. Any help here?
Thanks!
Edited by: dthornton on Jan 15, 2010 11:48 AM
I'm now looking for a way to show that result as a percentage of all records returned
Sure. Lets assume you have a formula @DaysDiff which is calculating the days difference between two days. Not let's say you have a running total RT_OneDaysDiff which is counting your records but only when @DaysDiff = 1. If you want to know the percentage of records where Days Diff = 1 compared to the total number of records, you would create a formula as followis:
if @count(rowidentifier) <> 0
then @RT_OneDaysDiff / count(rowidentifier)
Fuskie
Who would then repeat for each desired number of days difference...
Similar Messages
-
Get Column sum, count in sql developer
Dear All seniors,
I need help in oracle sql developer that after select statement when we got our result in below rows and coloums,
then how to get its sum, count, etc.
as in pl sql developer we simply right click at a column and then click on the desired function.
is this facility also have in sql developer?We've kicked around the idea of doing this for awhile. I believe there's already an item in the Exchange if you want to up vote it. The challenge being if it's a result set which hasn't been fully fetched, doing an aggregate would require one - and that could be costly. Of course folks live in the grids so I see the value in this type of feature as well.
As a workaround, you could of course export your data to CSV or XLS and do the calculations in your favorite spreadsheet software. -
How to print SUM & COUNT at the end of the XML template
Hello,
I am generating a payment file in oracle Payments and at the end of the file, I would also like to add a trailer record with sum of the payments and number of payments. Can anyone have any suggestions on having a trailer record with SUM & COUNT.
Thanks,You can use,
COUNT and SUM of the column to get those values.
In extext, add a new record and add these function on columns. -
Getting Sum, Count and Distinct Count of a file
Hi all this is a UNIX question.
I have a large flat file with millions of records.
col1|col2|col3
1|a|b
2|c|d
3|e|f
3|g|h
footer****
I am supposed to calculate the sum of col1 =9, count of col1 =4, and distinct count of col1 =c3
I would like it if you avoid external commands like AWK. Also, can we do the same by creating a function?
Please bear in mind that the file is huge
Thanks in advanceThis sounds like homework for a shell class, but here goes. Save into a file, maybe "doit". Run it like this:
$ ./doit < data
<snip>
#!/bin/sh
got0=0
got1=0
got2=0
got3=0
got4=0
got5=0
got6=0
got7=0
got8=0
got9=0
sum=0
cnt=0
IFS='|'
while read c1 c2 c3 junk; do
# Sum and count
echo "c1=${c1}"
case "${c1}" in
[0-9] )
sum=$(expr ${sum} + ${c1})
cnt=$(expr ${cnt} + 1)
esac
# Distinct
case "${c1}" in
0 ) got0=1;;
1 ) got1=1;;
2 ) got2=1;;
3 ) got3=1;;
4 ) got4=1;;
5 ) got5=1;;
6 ) got6=1;;
7 ) got7=1;;
8 ) got8=1;;
9 ) got9=1;;
esac
done
echo "cnt=${cnt}"
echo "sum=${sum}"
echo "distinct="$(expr $got0 + $got1 + $got2 + $got3 + $got4 + $got5 + $got6 + $got7 + $got8 + $got9)
<snip> -
Group queries (sum ,count, max,min)
can anyone tell how to use the group queries ? i dont know how to use exactly in abap. give the syntax and simple example with that group queries.
hi go through following logic,
it will solve ..
program1:DATA: AVERAGE TYPE P DECIMALS 2,
SUM TYPE P DECIMALS 2.
SELECT AVG( LUGGWEIGHT ) SUM( LUGGWEIGHT )
INTO (AVERAGE, SUM)
FROM SBOOK.
WRITE: / 'Average:', AVERAGE,
/ 'Sum :', SUM.
program2
PARAMETERS: TBLNAME(50) DEFAULT 'SPFLI'.
3 DATA: TOTAL_ROWS TYPE P.
4 SELECT COUNT(*) FROM (TBLNAME) INTO TOTAL_ROWS. ç
5 WRITE: / TBLNAME, TOTAL_ROWS.
for MAX and Min
SELECT MAX( MSGNR ) FROM T100 INTO C4A
WHERE SPRSL = 'D' AND
ARBGB = '00'.
SELECT MIN( MSGNR ) FROM T100 INTO C4A
WHERE SPRSL = 'D' AND
ARBGB = '00'.
if useful reward with points -
I have about 500 songs in my library that have played one time. Although a "last date played" date is noted, there is no number in the play count column. This only happens some times. Any reason for this, and can it be corrected? thx
Thanks, but the play count is not incrementing only on the very first play. All subsequent plays are fine. Meaning the play counts for these particular tracks are always one play short. I double-checked some of the tracks in question and I have not shortened, or stopped them early.
-
Right now, my report looks like:
Category invoice number invoice counter
A -
100----
1
Result -
1
B -
100----
1
Result -
1
Overall Result -
1
I know the overall result is correct, however the sum of category's result (2) is not equal to overall result.
Is there any way to show category A (or B) result as 0 since the invoice number is the same ?
Thanks!
Edited by: wawzj619 on Feb 5, 2010 12:00 AMHi.
Since the same invoice is valid for both categories, the correct value is what you are getting now.
However, you can consider implementing your own count, where you assign to each category the share of the invoice, either applying a weighted approach based on the invoice value for each category or unweighted. This will give you 0,5 invioces per category in your example and the total will be 1.
Thus it can and has beeen done, but I think counting this way is not logical as you will be getting fx 8,21 invoices for a category and how can you interpret this number? Or, in you example, category A did NOT receive just half an invoice! They got a whole one. And so did category B. The fact that it's the same invoice does not mean each category received just half an invoice!
If you want your overall result to be the sum of invioces across categories and thus display "2" in your example, you can set the "calculate results as..." to "total" for the counter key figure. But the number 2 would - to me - be incorrect, because you only got 1 invoice...
regards
Jacob -
My query looks like below , every thing works fine . Only I need in Sep 2014 I need Total ( instead of 2 should be 81) .
Select 'Reports' AS ReportName,
datepart(month,Date) [mn],
datepart(year,Date) [yr],
datename(month,max(Date))+' '+convert(varchar(4),datepart(year,max(Date))) [Month],
Count(ReportName)[CountReports]
from DB.dbo.Table1
group by datepart(month,Date),datepart(year,Date)
ReportName mn yr Month
CountReports
Reports 8 2014 August 2014
79
Reports 9 2014 September 2014 2
Any help will be appreciated
simamThat was an example which I have posted to illustrate how to get a running count within groups .
I've made some assumptions on your table schema, based on the query you have posted.
Here you go
drop table #temp
create table #temp
(ReportName varchar(30),
[Date] datetime
insert into #temp values ('rep1','1-jan-2014')
insert into #temp values ('rep2','2-jan-2014')
insert into #temp values ('rep3','1-jan-2014')
insert into #temp values ('rep4','1-feb-2014')
insert into #temp values ('rep6','1-feb-2014')
insert into #temp values ('rep6','1-feb-2014')
insert into #temp values ('rep6','1-Mar-2014')
insert into #temp values ('rep6','1-April-2014')
insert into #temp values ('rep6','1-Dec-2014')
insert into #temp values ('rep6','1-Nov-2014')
;WITH g AS
SELECT datepart(month,Date) [mn],
datepart(year,Date) [yr],
count(reportname) as cnt
FROM #temp
GROUP BY datepart(year,Date) ,Datepart(month,[Date])
SELECT 'Reports' name,mn,yr,
countreports = SUM(cnt) OVER (ORDER BY yr,mn ROWS UNBOUNDED PRECEDING)
FROM g
ORDER BY yr,mn
Hope this helps!! -
I have been working on this Select statement all day (blogs & testing) and I guess it's time to seek some help.
This is for my golf league to determine who is in the lead and determine the points each person has earned. Each week the golfer plays we enter data into a table (ParPoints) about the round and the 3 columns pertinent for this query are GolfID,
Season and Points. I suspect that I might come out of this with more than one Select statement and that is fine as I will be filling dataTables with the results before using it.
First off I only want rounds from this season (2014). Then I want to order the Points DESC for each GolfID & select the top 10 (10 best rounds by points). I only want 10 and 11-? aren't needed. I want to capture this raw data because I want
to report on it. It would be a great help to get this step completed.
Next using the raw data (above) I want to sum the points for each GolfID.
Then I want to count all of rounds actually played by each golfer. Actually If this has to be done by itself I can do it, but making it part of the bigger query I can not do.
So an help to get me started would be of great assistance.
Thanks
GaryHello,
If I understand correctly, you want to get the calculate the sum of top 10 [points] for each [GolfID] group as well as count the [points]of the group. Please refer to the following statement
--top 10 sum
;with cte as
(select golfid, season, points, row_number() over (partition by golfid order by points desc ) as point_order
from test )
select golfid, sum (points) as total
from cte
where season='2014' and point_order<=3
group by golfid
--count
select golfid, count(points) as count
from test
group by golfid
Regards,
Fanny Liu
If you have any feedback on our support, please click here.
Fanny Liu
TechNet Community Support -
Hey guys, sorry for a newbie question but here goes:
I have a table with col1, col2, col3, col4
where col1,col2 and col3 are values and col4 is the sum of the values.
The problem is that the sum column is currently empty and I was wondering how do I write a query that will add the sum to each row?
Thanks in advance for any help.Note that the posted solutions assume that col1, col2 and col3 are never null. If any of them could be null, then youe need to use NVL to avoid adding NULL to a number:
SQL> SELECT a, b, c, a + b + c total
2 FROM (SELECT 1 a, 2 b, 3 c FROM dual UNION ALL
3 SELECT 1, 2, NULL FROM dual);
A B C TOTAL
1 2 3 6
1 2Also, why do you need to store the sum of columns in the sa,e row. You should just do the adding when you select the records. It would be simple enough to create a view over the base table that does that.
John -
Dictionary, Table, Counter Question
Hi,
I'm trying to create a special customer table (SE11) with the following fields and have question regarding TYPE etc:
Fields of table
CUST_ID
CUST_NAME
CUST_DESC
1. CUST_ID should work as a counter (increment by 1 every time.) What kind of TYPE should I use ?
(How do i do the increment stuff...)
2. CUST_DESC should be able to take approx 5 kb of data and be searchable in WHERE clause. What kind of TYPE should I use ?
3. Is there any advantages of creating/using Data Element instead of Build-in type ?
//Martin
Message was edited by: Martin AnderssonHi Martin,
1. SE11 will help you only to create a table, but not to add any special functionality (as far as i have known) the CUST_ID can be made as counter only by programming. while moving data use a variable to get the previous maximum CUST_ID value from the tabel and increment it before you insert the value into the table.
2. To give long descriptions declare the CUST_DESC as LCHR or LRAW types, i am not sure whether it will hold 5kb of data. Then searching for a particular word will not be a problem you can use,
SEARCH <c> FOR <str> <options>.
<option> in the SEARCH FOR statement can be any of the following:
ABBREVIATED
STARTING AT <n1>
ENDING AT <n2>
AND MARK
can be used to find the required word.
3. I think this is what you meant - if a data element is created by a domain, the technical attributes of the domain are inherited by data elements and these domains can be used by any number of data elements, besides you can also create data elements by refering to the existing data elements using 'TYPE'.
Hope this helps.
Regards,
Kathirvel -
Hi Guys,
Can't really figure out where to start whit this one.
Table1: employees agenda, there has been a meeting where all the employees have spent 45 minutes each
EMP_NR
TIME CNT_NR
1792
45 31385920
1831
45 31385920
5469
45 31385920
2159
45 31385920
2272
45 31385920
7827
45 31385920
7652
45 31385920
2455
45 31385920
4353
45 31385920
Table2: the clients that have been discussed in that meeting
CL_NR
CNT_NR
22546
31385920
24575
31385920
27789
31385920
Objective:
Find all the records per CNT_NR (9 in the example of TABLE1) in TABLE1 and sum the total time (9*45=405). The total
time has to be divided over the number of records found in TABLE2 with the same CNT_NR. So in this case it would be 405 minutes divided by 3 clients = 135 minutes per client. The total time per client (135 min) can be displayed in a separate colomn.Please
don't use this specific CNT_NR, this varies.Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for:
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
Your picture is a mess. TIME is a data type in SQL, so it can not be a column name. We can have longer data element names in 2015; you are still stuck back in FORTRAN I where we were limited to six characters. What the heck is a “CNT”? Every guess I make is
obscene. Rows are not records; that is more 1960's FORTRAN!
Here is a guess at repairing this:
CREATE TABLE Agenda
(emp_id CHAR(4) NOT NULL PRIMARY KEY
REFERENCES Personnel(emp_id),
meeting_duration INTEGER NOT NULL
CHECK (meeting_duration > 0),
meeting_nbr CHAR(8) NOT NULL);
INSERT INTO Agenda
VALUES
('1792', 45, '31385920'),
('1831', 45, '31385920'),
('2159', 45, '31385920'),
('2272', 45, '31385920'),
('2455', 45, '31385920'),
('4353', 45, '31385920'),
('5469', 45, '31385920'),
('7652', 45, '31385920'),
('7827', 45, '31385920');
CREATE TABLE Clients
(client_id CHAR(5) NOT NULL PRIMARY KEY,
meeting_nbr CHAR(8) NOT NULL);
INSERT INTO Clients
VALUES
('22546', '31385920'),
('24575', '31385920'),
('27789', '31385920');
>> Find all the records [sic] per client_nbr (9 in the example of Agenda) in Agenda and sum the total time (9*45=405). The total time has to be divided over the number of records [sic] found in Clients with the same client_nbr. So in this case it would
be 405 minutes divided by 3 clients = 135 minutes per client. The total time per client (135 min) can be displayed in a separate column. Please don't use this specific client_nbr, this varies. <<
WITH Meeting_Duration (meeting_nbr, meeting_duration_tot)
AS
(SELECT meeting_nbr, SUM(meeting_duration)
FROM Agenda
GROUP BY meeting_nbr),
Client_per_Meeting (meeting_nbr, client_cnt)
AS
(SELECT meeting_nbr, COUNT(client_id) AS client_cnt
FROM Clients)
SELECT meeting_nbr,
(meeting_duration_tot/client_cnt) AS client_duration
FROM Meeting_Duration AS D,
Client_per_Meeting AS C
WHERE C.meeting_nbr = D.meeting_nbr;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
WSA / CWS Licensing count question.
Hello,
I have a question how WSA and CWS are licensed based on the number of users.
Is it based on concurrent or named users, active sessions based on source IP address or another way? This old post mentions concurrent users but based on a legacy ironport ordering guide. And that document does not mention any licensing methods.
https://supportforums.cisco.com/message/3949429
However for CWS i found this post:
https://supportforums.cisco.com/message/4003674
For the sizing it mentions: "It will be total number of CWS users, not concurrent users". Sizing is nog licensing, but the CWS datasheet mentions "The Cisco Web Security portfolio uses tiered pricing based on the number of users".
I believe there are licenses allowing mixed use of CWS and WSA in combination with the free Virtual Applicances. Is this correct and how does this reflect on my question regarding user licensing?Hi,
It's based on the number of named users, however there is no absolute way to count the users so it's a trust thing too and you should be honest about how many users you have.
Thanks
Chris -
Counter Questions Using PCI6602
I have a couple of questions regarding the operation of the PCI6602. I am programming in VB.NET.
Can you have multiple tasks that each correspond to one Counter Input Channel being used at the same time (i.e. trying to read a small angle inside another larger angle using encoders)?
Is there any way to setup a trigger based on a counter count value (i.e. once the count value hits 180 degrees raise a digital bit)?Justin,
You cannot have two tasks running simultaneously that are using the same counter input channel. You can, however, connect the same signal to two of your counter channels and have two tasks monitoring the two different channels.
As far as triggering off of a counter value. The best that you can do is a software trigger. In DAQmx, in LV 7.1 you can do a timed loop that waits for the event to occur (i.e. counter reaching a value). I am not aware of this implementation in VB, but it is still nothing more than a fancy software trigger. You would need to poll the counter and then run the DIO task when it reaches its value. -
I'm being stupid, again. Sum & Count, together
Hi-
I thought that this should be easy and I was able to do this...nope.
i need to sum a value for each distinct count. Having read a few post, i think i need an over() function.
select distinct
[Training Title],
[Training Type],
count(CASE WHEN [user id] IS NULL THEN 0 ELSE 1 END) as 'Number',
sum(cast([training hours] as float)) as 'Total Hours',
count([training object id]) as 'Offerings'
-- this is duping, think i need an count([training object id]) over(PARTITION BY [TRAINING TITLE] )
from q2_2014
where [training type] = 'session'
group by
[Training Title],
[Training Type]data:
Training Title
user id
training hours
training object id
crs1
a1
0.25
id-1
crs1
b1
0.25
id-1
crs1
c1
0.25
id-2
crs1
d1
0.25
id-2
csr2
a1
0.25
id-1a
crs2
b1
0.25
id-1b
crs3
a1
0.25
id-1
results:
Training Tile
Count Users
Total Hours
Number of Offerings
crs1
4
1
2
crs2
2
0.5
2
crs3
1
0.25
1
Maybe you are looking for
-
Simply...I have QT Pro 7.6.3 and QT X. But when I try to view the new commercials on the Apple site (and other online video), it tells me I need to have quicktime and directs me to download it. Ideas on a fix? TIA
-
NWDS installation issue.
Hello, I have installed NWDS on my pc and I have a minor issue with it: When you first run the NWDS after the installation, an eclipse window appears saying "Please wait... completing the install". The problem in my installation is that I see this wi
-
Photoshop Elements 10 disc is rejected by new iMac running OS 10.8.2
I am trying to load Elements 10 on to my new iMac .I have the SuperDrive which takes the disc, but then ejects it again, so I have not been able to instal. This latest iMac has Intel chips, and Elements comes with 3 discs, only one of which is used
-
Email attachment download limits
Hi, Is there a restriction on Email attachments that stops you from downloading them if they are too large? I can download most attachments but I just received a 10MB file and it doesn't download any of the file, appears that it is trying but I have
-
Exception when trying to manipulate Data in an ADAM server
Hi all, I'm having problems with trying to manipulate data in the ADAM instance on my machine. Currently I can bind to the ADAM instance (took me a while to figure out that ADAM isn't like other normal LDAP servers... you need to bind as a user which