Help with Max Count
Given this info:
ID Name Class ID Location ID Location Name
101 John Smith 1001 1A Location 1
101 John Smith 2002 2B Location 2
101 John Smith 3003 2B Location 2
101 John Smith 4004 3C Location 3I want to be able to get this output:
ID Name Max Location
101 John Smith Location 2 Using this:
Select id, name, MAX("Amt") from (select id, name,
(case when location_id = '1A' then Count(pidm_key)
when location_id = '2B' then Count(pidm_key)
when location_id = '3C' then Count(pidm_key) else null end) "Amt"
from Table1
group by id, name, location_id)
group by id, name
I get:
ID Name Amt
101 John Smith 2 But of course I want the other output.
What is you db version?
you can use the KEEP syntax for the max aggregate in the outer query.
Along the lines of
not syntax checked
MAX(location_name) keep (dense_rank last order by "Amt")
Similar Messages
-
I am a rookie and need help with max and min values
Hello all, i am into this intro to java class. my assignment is to write a program that prompts the user for two integers and then prints the sum, difference, average, product , distance (absolute value of the difference) Maximum(largest of the two) and Minimum(smallest fo the two) here is my code so far
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Math;
public class Sample4
public static void main(String[] args) throws IOException
try // attempt the following
{ // create the stream to read from
InputStreamReader istream = new InputStreamReader(System.in); // create a buffer to hold the stream
BufferedReader console = new BufferedReader(istream); // prompt the user
System.out.println("Enter a number please"); // get input as a string
String input = console.readLine(); // convert to an integer
int num1 = Integer.parseInt(input);
System.out.println("Enter a number please"); // get input as a string
String input2 = console.readLine(); // convert to an integer
int num2 = Integer.parseInt(input2);
int sum = num1 + num2; // get the sum of the two inputs
int difference = num1 - num2; // get the difference of the two inputs
int product = num1 * num2; // get the product of the two inputs
int average = sum / 2; // get the average of the two inputs
int abs = Math.abs(difference); // get the absolute value of the two inputs
// new section
// display the number
System.out.println("The total sum = " + sum);
System.out.println("The total difference = " + difference);
System.out.println("The total product = " + product);
System.out.println("The total average = " + average);
System.out.println("The total absolute value = " + abs);
} // if something breaks, catch the exception
catch (IOException e)
System.out.println(e); // displays the exception
System.exit(1); // quits the program
}what will be the right syntax or code to find the MAX and MIN values of two numbers a User Inputs, hope someone can help with this. thank you for your help.Thanks alot man, sheesh i do not know why my book
doesnt give me all the static methods. but i do really
appreciate your help. peaceA complete list of the java.lang.Math methods can be found at http://java.sun.com/j2se/1.4/docs/api/java/lang/Math.html
btw,
max(a, b) == (a > b) ? a : b
min(a, b) == (a < b) ? a : b -
Need some help with a counting function
Hello,
I use a simple sheet to organize the timetable of my patients. Now I'd like to count how many different patients I attend, without counting a patient twice if I attend him twice a week for example. My sheet looks like this:
Mon
Tue
Wed
Thu
John
Steve
John
Wesley
Mary
Harry
Deborah
Peter
Arnold
Carol
Chris
Mary
Sarah
Karen
Karen
Carol
Larry
Peter
So the answer would be 13, because I attend 13 different patients a week. Fields in blank should no be counted, the cell contend changes frequently.
A friend of mine tried to help me with a countif function but it didn't work out for me, it would count the fields left blank too.
Any idea?
Thanks, gabrielHi Gabriel,
Here's another, more generalized, approach that doesn't need adjusting for maximum number of visits/week at the cost of just a few more formulas. But only two tables!
Formula in A2 and copied down:
=ROUNDUP((ROW(cell)−1)÷$B$27,0)
Formula in B2 and copied down:
=IF(MOD(ROW(cell)−1,$B$27)=0,$B$27,MOD(ROW(cell)−1,$B$27))
The formula in C2 and copied down:
=OFFSET(Schedule::$A$1,0,B−1)
The formula in D2 and copied down:
=IFERROR(OFFSET(Schedule::$A$1,A2,B2−1,rows,columns),"")
The formula in E2 and copied down:
=IF(AND(D2≠0,LEN(D2)>0),COUNTIF($D$1:D2,D2),"")
The formula in F2 and copied down:
=IFERROR(IF(E=1,1,""),"")
The formula in F27: =SUM(F)
The value in B27 is 4, the number of day columns in the Schedule table. You would change that if you increase or decrease the number of days on which you see patients.
Column C is cosmetic, not needed in the calculation.
The error triangle means all of the cells in the Schedule table are already accounted for in the rows above.
Probably more compact ways to do this but it gets the job done.
SG -
Need help with MAX function to return values
I am trying to create a report to return slow moving inventory data. One of the requests is that it return only the latest date that an item transacted upon. One sheet will show the last receipt date for a part, another will show the last time a part was issued or shipped on a sales order.
The hiccup is that it is returning every single last time that an item was received, and every single last issuance of the material (on the second sheet) of items on hand.
Could someone help me to define the max value function? As listed below, and many variations, the sheet comes up with no data or corrupt dates.
MAX(Transaction Date MAX) OVER(PARTITION BY Material Transactions.Item ORDER BY Material Transactions.Item )
Still returns both the following when in reality I just want the one with the most recent date (April 2010).
100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT A400M AB01D.. $0.00 WIP component issue 11-Sep-2009 -3
100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT A400M AD01D.. $0.00 WIP component issue 13-Apr-2010 -16
Thank you for your assistance.
BeckaHi Becka
It does look correct. When I look at your data I can see 2 different items:
100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT A400M AB01D.. $0.00 WIP component issue 11-Sep-2009 -3
100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT A400M AD01D.. $0.00 WIP component issue 13-Apr-2010 -16
One is AB01D and the other being AD01D. Is this expected?
To get the right date you might want to PARTITION BY the BNDSCE-105 which might be the Item Number?
If you can get your calculation to return the correct date then you next need to put in a new condition where the Transaction Date = MAX Transaction Date
One part of the function that I would question is the use of MAX in both parts like this: MAX(Transaction Date MAX). You might be better just using MAX(Transaction Date) OVER ......
Does this help?
Best wishes
Michael -
Help with inserting counter code
hi friends, i want to put an invisible counter on my website but i cant seem to do it. i got the counter code from statcounter and i also downloaded a trial version of bbedit. in bbedit when i do a search for the code i have to replace bbedit comes up with nothing on the search, im not html savy in the slightest...can somebody walk me through this step by step.
If you want to insert the code by hand, just open each page.html file and scroll to the end. You will see a <body><html> tag. Just copy and paste your code before the <body> tag and the save.
But if you want an easy and automatic way to do this for your pages...just download iComment 3.0. Launch it and paste your StatCounter code in the appropriate window. Then point iComment to your Sites folder and click Go. It will place the StatCounter code on every page in your site.
If you don't want to do the Haloscan commenting, you can just leave that blank in iComment.
James
http://www.dirtdoog.com/ -
Help with "distint count" in query
Hi
I have a query that returns the following error:
ORA 00936: Missing Expression
and also after running it again
I get ORA 00900: Invalid SQL statement.
The query is as follows:
SELECT
DISTINCT student_id,
COUNT(student_id),
ABSENCE_REASON_CODE,
calendar_date,
attendance_status,
FROM AT_HOURLY_ATTENDANCE_RECORDS
WHERE (absence_reason_code = 'UC')
OR (absence_reason_code = '1');all help is gratefully acknowledged. Thanks in advanceHi
Thanks to both guys for helping me out.. (Steven and Gasparatto)
The query still has the following problem:
ORA-00900: invalid SQL statement
I wonder why this is happening..
(Toad is pointing out student_id as a possible culprit
the code again is:
SELECT
DISTINCT student_id,
COUNT(student_id),
ABSENCE_REASON_CODE,
calendar_date,
attendance_status
FROM AT_HOURLY_ATTENDANCE_RECORDS
WHERE (absence_reason_code = 'UC')
OR (absence_reason_code = '1');Please excuse me for my naive questions. I have learnt a lot today itself. Thanks a lot again -
Help with arrays & counting characters in arrays
I am trying to figure out how to count how many times each characters appears in the array (but I have to do all the counts at once).
I am supposed to store the counts in an int[] array of 27 elements (26 letters & an extra count for everything else). How would I go about declaring the array, allocating it, & then setting each of the 27 elements zero?
Thanks so much the help.
public class CharCount {
public static void main(String[] args) {
new CharCount().process();
public void process() {
// This declares an array of char and then assigns it a value. The value comes from another one
// of my secret programs.
char[] countThese = Lab8.simple();
printChars(countThese);
for (int count =0; count < countThese.length; count++) {
System.out.println(countThese[count]);
// This method should print the characters in the array called print, one-by-one
// Use a println ONLY after all the chars have been printed.
public void printChars(char[] print) {
public int charToInt(char ch) {
if (ch >= 'A' && ch <= 'Z')
return ch - 'A';
else if (ch >= 'a' && ch <= 'z')
return ch - 'a';
else return 26;
}I take it the charToInt method was given to you. If you don't know what it does, it will give you a value from 0 to 26 depending on what char you pass as a parameter. So if you pass an 'a' or an 'A' it will return 0, 25 for 'z' or 'Z' and 26 for anything else. You use this value to access an array an increment the value (the number of times that letter has occured.
int value = charToInt('a');
arr[value]++;
System.out.println("Number of a's = " + arr[0]); -
Need help with voltage counter
I have a system that passes current through a resistor when ever a button is pushed. The voltage across the resistor (about 100mV) is read by a cFP-AI-102 Analog Input voltage module. I'm trying to figure out a way to count the number of times this happens. In other words, I need to count how many times the button is pushed.
I've tried using a While Loop, but since it counts with every iteration I end up with way too many counts for each button push. Is there a way I only count once?
Thanks,
EricHi!
If I understand, you want to measure how many times button is pushed, i.e. how many transition 0 -> 100 mV, right? I'd do that with a shift register and a while loop.... just save the past state of the analog in, if the comparison between the past state and curtrent state is > 50 mV, you have a push.... (actually it depends on how terminals are connected...)
Post your code, perhaps I can understand better the starting point.
remember: this way you're going to measure too many transitions, because usually, when a button is pressed or released you have some oscillating voltage (I don't know if you ever tried to handle a switch button with a microcontroller, there you can see this). But maybe, AI module sample at "low frequencies" respect to this phenomenon.
graziano -
Help with number counting project
the program is supposed to let the user enter numbers and and then return the numbers they entered and how many times they entered each one. this is what i have so far and i dont know what i need to put next so can anybody give me a hint or help me please thanks
* Joey McCashland
* 02/04/08
* CS3 AP
* PP 6.1
import java.util.*;
public class PP6_1
public static void main()
ArrayList dean = new ArrayList();
Scanner s = new Scanner (System.in);
int num = 0;
while(( num <= 50) && (num >= 0 ));
System.out.println("Enter any integers from 0 to 50. Enter -1 to stop");
num = s.nextInt();
dean.add(num);
System.out.println(num);
}Edited by: Encephalopathic on Feb 17, 2008 6:02 PM
-
Help with a COUNT query...
I have created the following tables:
create table ZONE (
ZoneNo number(2),
State char(3),
PRIMARY KEY (ZoneNo)
create table SCHOOL (
SchoolType char(1),
SchoolNumber number(4),
SchoolName char(40),
SchoolZone number(2),
PRIMARY KEY (SchoolNumber,SchoolType),
FOREIGN KEY (SchoolZone) REFERENCES ZONE
create table TEACHER (
TeacherCode char(5),
Surname char(30),
FirstName char(30),
Gender char(1),
WorksFor number(4),
YearCommenced number(4),
LivesIn number(2),
TeachingType char(1),
PRIMARY KEY (TeacherCode),
FOREIGN KEY (WorksFor, TeachingType) REFERENCES SCHOOL(SchoolNumber,SchoolType),
FOREIGN KEY (LivesIn) REFERENCES ZONE
create table COMPUTER (
SerialNumber char(10),
Description char(50),
RegisteredTo char(5),
PRIMARY KEY (SerialNumber),
FOREIGN KEY (RegisteredTo) REFERENCES TEACHER
My question is, how would i make a COUNT (or similar) query that would display each SchoolName and show the total amount of teachers who work at that school in the second column?Yes, it needs to join all columns on foreign key.
This is usual, gentle, safety, and universal approach.
insert into ZONE values (6,'CA');
insert into SCHOOL values ('E',600,'Oracle Elemental School',6);
insert into SCHOOL values ('J',600,'Oracle Middle School',6);
insert into SCHOOL values ('S',600,'Oracle High School',6);
insert into TEACHER values (12001,'Suzuki','Akiko','F',600, 2005, 6, 'E');
insert into TEACHER values (12002,'Scott','Tiger','M',600, 2005, 6, 'E');
insert into TEACHER values (12003,'Zhong','San','M',600, 2005, 6, 'J');
insert into TEACHER values (12004,'Li','Si','M',600, 2005, 6, 'J');
insert into TEACHER values (12005,'Wang','Wu','M',600, 2005, 6, 'J');
insert into TEACHER values (12006,'Kim','Youngae','F',600, 2005, 6, 'S');
insert into TEACHER values (12007,'Kim','Jiu','F',600, 2005, 6, 'S');
insert into TEACHER values (12008, null,'Joe','M',600, 2005, 6, 'S');
column schoolname format a30
set lines 120
select s.SchoolName
,count(*) "ALL"
,count(t.TeacherCode) "ALL(CODE)"
,count(distinct t.TeacherCode) "DISTINCT(CODE)"
,count(t.surname) "ALL(NAME)"
,count(distinct t.surname) "DISTINCT(NAME)"
from School s, Teacher t
where s.SchoolNumber = t.WorksFor
and s.SchoolType = t.TeachingType
group by s.SchoolName
SCHOOLNAME ALL ALL(CODE) DISTINCT(CODE) ALL(NAME) DISTINCT(NAME)
Oracle Elemental School 2 2 2 2 2
Oracle High School 3 3 3 2 1
Oracle Middle School 3 3 3 3 3select s.SchoolName
,count(*) "ALL"
,count(t.TeacherCode) "ALL(CODE)"
,count(distinct t.TeacherCode) "DISTINCT(CODE)"
,count(t.surname) "ALL(NAME)"
,count(distinct t.surname) "DISTINCT(NAME)"
from School s, Teacher t
where s.SchoolNumber = t.WorksFor
--and s.SchoolType = t.TeachingType
group by s.SchoolName
SCHOOLNAME ALL ALL(CODE) DISTINCT(CODE) ALL(NAME) DISTINCT(NAME)
Oracle Elemental School 8 8 8 7 6
Oracle High School 8 8 8 7 6
Oracle Middle School 8 8 8 7 6 -
Help with looping and counting
i am in a CS 1 class and need help with this loop
/*Write a program that will allow the user to enter a character
until the capital letter Z is entered
The program should count the number of letters entered
and print the total after the loop is completed*/
here is what i have it doesn't end nor does it count and i don't know hwo to make it count also i suck at do..while loops hehe
char b,Z=0;
Scanner a = new Scanner(System.in);
do
System.out.print("Enter a letter: "+"\n");
b=a.next().charAt(0);
while (b !=Z);
i know that its not even close to being right just help me out here
Edited by: purplesmurf on Nov 14, 2008 7:25 PMThe following program will count the number of chacters entered until Z is enetered.
import java.io.*;
class count
public static void main(String[] args)throws IOException
char ch;
int cnt=0;
DataInputStream br=new DataInputStream(System.in);
do
System.out.print("Enter a character:");
ch=(char)br.read();
if(ch!='Z')
cnt++;
else
break;
}while((ch=(char)br.read())!='Z');
System.out.println("The Number of entered characters are:"+cnt);
} -
Hi everyone,
I am writing this page for users to register and to login, but the problem i have is knowing who are the most active users.
I am trying to do this with a hit counter, as you can see in my last "if", but is not working as it should be.
Can somebody help with this.
thanks.
<html>
<head>
<title> 2 </title>
</head>
<body>
<body bgcolor="#FFFFFF">
<center>
<br>
<%
Cookie[] cookies = request.getCookies();
if (cookies == null){
cookies = new Cookie[0];
Cookie c = new Cookie("users","");
response.addCookie(c);
String username = request.getParameter("username");
String password = request.getParameter("password");
Cookie newuser = null;
if (username!=null && password!=null && username.length()>0) {
newuser = new Cookie(username,password);
response.addCookie(newuser);
for (int i=0; i<cookies.length; i++) {
if (newuser!=null && newuser.getName().equals(cookies.getName())){
newuser = null;
out.println("><BR> <H3>" + "That username already exists, please enter another."+"<BR> </H3>");
if (newuser != null){
out.println("<H3> Welcome new user: <BR>"+newuser.getName()+":\t"+ newuser.getValue()+"<BR> </H3>");
int counter = 0;
if (request.getParameter("registereduser") != null){
for (int i=0; i<cookies.length; i++) {
if (request.getParameter("registereduser").equals( cookies[i].getName() ) ){
out.println("><BR> <H3>" + "Welcome again, "+ cookies[i].getName()+counter++"<BR> </H3>");
%>
</center>
</body>
</html>I'm trying to do it this way:
I have declared an static counter to do the task, and is incrementing everytime the page is visited, but,
I want that depending of the user, it will print a different output, for example:
user "a", visted 3 times,
or user "b" visited 8 times.
I was thinking in a counter for each user, and to save it and restore it every time the user visits.
how can i do that?
<%! static int staticCounter = 1; %>
<%
if (request.getParameter("registereduser") != null){
for (int i=0; i<cookies.length; i++) {
if (request.getParameter("registereduser").equals( cookies.getName() ) ){
out.println("><BR> <H3>" + "Welcome again, "+ cookies[i].getName()+staticCounter++"<BR> </H3>");
%> -
Hi I am using oracle 10g. Trying to aggregate duplicate count records. I have so far:
SELECT 'ST' LEDGER,
CASE
WHEN c.Category = 'E' THEN 'Headcount Exempt'
ELSE 'Headcount Non-Exempt'
END
ACCOUNTS,
CASE WHEN a.COMPANY = 'ZEE' THEN 'OH' ELSE 'NA' END MARKET,
'MARCH_12' AS PERIOD,
COUNT (a.empl_id) head_count
FROM essbase.employee_pubinfo a
LEFT OUTER JOIN MMS_DIST_COPY b
ON a.cost_ctr = TRIM (b.bu)
INNER JOIN MMS_GL_PAY_GROUPS c
ON a.pay_group = c.group_code
WHERE a.employee_status IN ('A', 'L', 'P', 'S')
AND FISCAL_YEAR = '2012'
AND FISCAL_MONTH = 'MARCH'
GROUP BY a.company,
b.district,
a.cost_ctr,
c.category,
a.fiscal_month,
a.fiscal_year;
which gives me same rows with different head_counts. I am trying to combine the same rows as a total (one record). Do I use a subquery?Hi,
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
user610131 wrote:
... which gives me same rows with different head_counts.If they have different head_counts, then the rows are not the same.
I am trying to combine the same rows as a total (one record). Do I use a subquery?Maybe. It's more likely that you need a different GROUP BY clause, since the GROUP BY clause determines how many rows of output there will be. I'll be able to say more after you post the sample data, results, and explanation.
You may want both a sub-query and a different GROUP BY clause. For example:
WITH got_group_by_columns AS
SELECT a.empl_id
, CASE
WHEN c.category = 'E'
THEN 'Headcount Exempt'
ELSE 'Headcount Non-Exempt'
END AS accounts
, CASE
WHEN a.company = 'ZEE'
THEN 'OH'
ELSE 'NA'
END AS market
FROM essbase.employee_pubinfo a
LEFT OUTER JOIN mms_dist_copy b ON a.cost_ctr = TRIM (b.bu)
INNER JOIN mms_gl_pay_groups c ON a.pay_group = c.group_code
WHERE a.employee_status IN ('A', 'L', 'P', 'S')
AND fiscal_year = '2012'
AND fiscal_month = 'MARCH'
SELECT 'ST' AS ledger
, accounts
, market
, 'MARCH_12' AS period
, COUNT (empl_id) AS head_count
FROM got_group_by_columns
GROUP BY accounts
, market
;But that's just a wild guess.
You said you wanted "Help with count and sum". I see the COUNT, but what do you want with SUM? No doubt this will be clearer after you post the sample data and results.
Edited by: Frank Kulash on Apr 4, 2012 5:31 PM -
Help with a Word Counting Program..
I need some help with a program I am trying to write
The program is being written in BlueJ.
Im just starting the program and am completely confused on how I should write this...
But here is what I have to do..
I have to use a scanner to scan a Text file and count the # of Words the number of Vowels (including Y when it is) and the # of Palindromes (Word spelled same forward and Back) as well as which Palindromes are being used.
It would be good to have a class to clean the text and a seperate class for the tasks...
I do not want to use anything other than "If" statements and while loops (no "for" loops) and only use Printwriter as the output file writer.
Thnx to anyone in advanceI have a basic Vowel coding that doeswnt work...
public class vowel{
String word = "heyyou";
String vowels = "aeiouy";
int[] countv = new int[vowels.length()];
int countv2;
int i=0;
if(i<word.length();) { i++ {
if (int j=0 && j<vowels.length()) {
return j++;
if (word.charAt(i)==vowels.charAt(j)) {
countV[j]++; countV2++;
for (int i=0; i<vowels.length(); i++) {
System.out.println("Vowel "vowels.charAt(i)" = "+vcnt);
System.out.println("Consonants = "+(word.length()-vtot)); }
I also have a basic Palindrome code that works as a boolean but I need to make it return what the palindromes are and how many of them are there. I wanna know how I would do this.
public class Palindrome{
public static boolean isPalindrome(String word) {
int left = 0;
int right = word.length() -1;
while (left < right) {
if (word.charAt(left) != word.charAt(right)) {
return false;
left++;
right--;
return true;
I would also like to know how to actually start writing the word counter. -
Help with Inconsistent data from NI6211
I'm not getting very far with establishing good data transfer from an NI 6211 and don't seem to be able to pin point the issue or get confidence from DasyLab V10 to be able to look for the problem in another area.
The NI6211 is set for period measurement and automatically uses a low frequency counter with sample on demand. The measurement range is set for 200ms to 1ms
The Dasylab Counter Input task displays the sample on demand and block size of "1".
I have also selected "10" as an output after timeout of 5seconds.
I have set the module to use the Dasylab timebase and have configured all 3 timebases for 1000Hz and (tried higher and lower values) and set block sizes to 1.
Whenever I change the timebase setting I always carry out a synchronise with MAX.
I have been writing to a file using time deducted from data.
With these settings I have the value "10" generated and stored in the file.
When it says "Output after timeout (s) of:", does this mean that their has been no communication for 5seconds even though I can get time stamp information indicating only a few milliseconds have passed?
Does time deducted information mean time deduced information (ie. time stamp from the data)
Is there anything I need to do with A/D window? I have changed the sampling rate in there but it only appears to change the driver setting.
Any help much appreciated.
Thanks
Mark..Additional to information in above post, the operating system is Windows Vista Home Premium with Service Pack 1.
Could this be the underlying issue, Dasylab and Windows Vista are untested?
Thanks
Maybe you are looking for
-
Issue while submitting concurrent program from OAPage
Hi Team, In OApage in One LOV field is der. From that LOV we need to select one concurrent program and click next button. while clicking on the next button i am getting error like below The data that defines the flexfield on this field may be incons
-
Statspack taking too much time
Hi when t try to execute exec perfstat.statspack.snap(i_snap_level=>10);it is taking too much time..... can anybody suggest me for the same....
-
Hi everyone, I learn OData and SAPUI5. for tutorial I find this document http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40d59930-791c-3010-2abd-ac7793ad6c57?QuickLink=index&- I faced some problems. 1) when I click the 'Call Browse
-
Replacing photos in catalog ...
Hi, I have about 50 images in a LR3 catalog. I modified all the metadata for each. They are all jpegs and were pre-processed by a specialized image editing program before import. I now find I have to replace all 50 with new versions. I really don't w
-
Every time. And there's no obvious way to avoid it.