Help with Query

  • Thread starter Thread starter Maureen
  • Start date Start date
M

Maureen

Is there any way in a query to do a running total like
records?

the output that I am trying to acheive is this:

teacher class period student stu_no
Mr. A A 1 Joe 1
Mr. A A 1 Bob 2
Mr. A A 1 Jim 3
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

I have been trying everything with count but all I can
acheive is a complete total - what I really need is a
running total.

I would REALLY appreciate any help.
thank you in advance
 
I don't think you can get a running total without an ORDER BY. I didn't
notice an ORDER BY in your sample that matched anything that looked like a
running sum. I like puzzles but it would help if you would describe the
pattern.
 
The order by is Teacher, class, period
each row that has a different student would cause the
stu_no to increase by 1.
When the next row has a new Teacher, class or period, the
stu_no would start at 1 again.

Basically counting and number each student for each
teacher, class, period.
 
I was looking at the query and with a totals query there
is no order by only group by.
-----Original Message-----
The order by is Teacher, class, period
each row that has a different student would cause the
stu_no to increase by 1.
When the next row has a new Teacher, class or period, the
stu_no would start at 1 again.

Basically counting and number each student for each
teacher, class, period.
 
All query designs allow sorting. Is this query going into a report? If so,
you should do your counting there. If not, come on back.

--
Duane Hookom
MS Access MVP


Maureen said:
I was looking at the query and with a totals query there
is no order by only group by.
 
I do need the counting to occur at either the query level
or at the table level.

I am sorting by teacher, class, period > this is where I
need to have the stu_no > to number each student that
falls into that section.

If it were feasible and a onetime thing - I would create
several tables for each teacher, class, period and make
an autonumber for the stu_no - then just join them
together.

However, this data is always going to be changing as it
is a schedule.

I am REALLY stuck with this and don't know the way to
accomplish the output.

I would appreciate any help at all that you could offer.

thank you
 
You need to add Student to the sort. Also, I asked if this was going to a
report where the numbering would be much easier. The following query assumes
your table name is tblA. Change all "tblA" to your table or query name.

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM tblA A
WHERE A.Teacher = tblA.Teacher
AND A.Class = tblA.Class
AND A.Period = tblA.Period
AND A.Student <=tblA.Student) as Stu_No
FROM tblA
ORDER BY Teacher, Class, Period, Student;
 
I am unable to make the query example that you gave me
work. I receive the message "You tried to execute a
query that does not include the specified
expression "Teacher" as part of an aggregate function."

it looks like this:
SELECT DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT, Count(*) AS STuNo
FROM DailySchedData INNER JOIN testA ON
(DailySchedData.Shift = testA.Shift) AND
(DailySchedData.PosNum = testA.PosNum)
AND (DailySchedData.Class = testA.Class)
AND (DailySchedData.TEACHER = testA.TEACHER)
WHERE (((testA.STUDENT)<=[DailySchedData]![STUDENT]))
ORDER BY DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT;

I know that the numbering would be easier at the report
level, if I could get away with that I would do it in a
second. However, I have to create a way to number the
students based on Teacher, Class, Period. - This numbers
corresponds to an already in-place schedule system.

Is there anything else that I can try?
Or to alter the query?

thank you for your help
 
Your query doesn't resemble mine suggestion. I had two "SELECT " in my query
versus your one. Try this:

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM DailySchedData A
WHERE A.Teacher = DailySchedData.Teacher
AND A.Class = DailySchedData.Class
AND A.Period = DailySchedData.Period
AND A.Student <= DailySchedData.Student) as Stu_No
FROM DailySchedData
ORDER BY Teacher, Class, Period, Student;

--
Duane Hookom
MS Access MVP
--

Maureen said:
I am unable to make the query example that you gave me
work. I receive the message "You tried to execute a
query that does not include the specified
expression "Teacher" as part of an aggregate function."

it looks like this:
SELECT DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT, Count(*) AS STuNo
FROM DailySchedData INNER JOIN testA ON
(DailySchedData.Shift = testA.Shift) AND
(DailySchedData.PosNum = testA.PosNum)
AND (DailySchedData.Class = testA.Class)
AND (DailySchedData.TEACHER = testA.TEACHER)
WHERE (((testA.STUDENT)<=[DailySchedData]![STUDENT]))
ORDER BY DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT;

I know that the numbering would be easier at the report
level, if I could get away with that I would do it in a
second. However, I have to create a way to number the
students based on Teacher, Class, Period. - This numbers
corresponds to an already in-place schedule system.

Is there anything else that I can try?
Or to alter the query?

thank you for your help
-----Original Message-----
You need to add Student to the sort. Also, I asked if this was going to a
report where the numbering would be much easier. The following query assumes
your table name is tblA. Change all "tblA" to your table or query name.

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM tblA A
WHERE A.Teacher = tblA.Teacher
AND A.Class = tblA.Class
AND A.Period = tblA.Period
AND A.Student <=tblA.Student) as Stu_No
FROM tblA
ORDER BY Teacher, Class, Period, Student;



--
Duane Hookom
MS Access MVP
--




.
 
Pardon me, for missing that.
I tried with the second select and
unfortunately this gives a total number of records.
The result is:

Teacher Class Period Student Stu_No
Mr. A A 1 Joe 159
Mr. A A 1 Joe 159
Mr. A A 1 Bob 159
Mr. A A 1 Jim 159
Mr. A A 2 Sue 159
Mr. A B 1 Jon 159

What I need is:
Teacher Class Period Student Stu_No
Mr. A A 1 Joe 1
Mr. A A 1 Joe 2
Mr. A A 1 Bob 3
Mr. A A 1 Jim 4
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

Can't this be done?
-----Original Message-----
Your query doesn't resemble mine suggestion. I had two "SELECT " in my query
versus your one. Try this:

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM DailySchedData A
WHERE A.Teacher = DailySchedData.Teacher
AND A.Class = DailySchedData.Class
AND A.Period = DailySchedData.Period
AND A.Student <= DailySchedData.Student) as Stu_No
FROM DailySchedData
ORDER BY Teacher, Class, Period, Student;

--
Duane Hookom
MS Access MVP
--

I am unable to make the query example that you gave me
work. I receive the message "You tried to execute a
query that does not include the specified
expression "Teacher" as part of an aggregate function."

it looks like this:
SELECT DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT, Count(*) AS STuNo
FROM DailySchedData INNER JOIN testA ON
(DailySchedData.Shift = testA.Shift) AND
(DailySchedData.PosNum = testA.PosNum)
AND (DailySchedData.Class = testA.Class)
AND (DailySchedData.TEACHER = testA.TEACHER)
WHERE (((testA.STUDENT)<=[DailySchedData]![STUDENT]))
ORDER BY DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT;

I know that the numbering would be easier at the report
level, if I could get away with that I would do it in a
second. However, I have to create a way to number the
students based on Teacher, Class, Period. - This numbers
corresponds to an already in-place schedule system.

Is there anything else that I can try?
Or to alter the query?

thank you for your help
-----Original Message-----
You need to add Student to the sort. Also, I asked if this was going to a
report where the numbering would be much easier. The following query assumes
your table name is tblA. Change all "tblA" to your
table
or query name.
SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM tblA A
WHERE A.Teacher = tblA.Teacher
AND A.Class = tblA.Class
AND A.Period = tblA.Period
AND A.Student <=tblA.Student) as Stu_No
FROM tblA
ORDER BY Teacher, Class, Period, Student;
in
message
I do need the counting to occur at either the query level
or at the table level.

I am sorting by teacher, class, period > this is
where
I
need to have the stu_no > to number each student that
falls into that section.

If it were feasible and a onetime thing - I would create
several tables for each teacher, class, period and make
an autonumber for the stu_no - then just join them
together.

However, this data is always going to be changing as it
is a schedule.

I am REALLY stuck with this and don't know the way to
accomplish the output.

I would appreciate any help at all that you could offer.

thank you
-----Original Message-----
All query designs allow sorting. Is this query going
into a report? If so,
you should do your counting there. If not, come on back.

--
Duane Hookom
MS Access MVP


"Maureen" <[email protected]>
wrote
in
message
I was looking at the query and with a totals query
there
is no order by only group by.
-----Original Message-----
The order by is Teacher, class, period
each row that has a different student would
cause
the
stu_no to increase by 1.
When the next row has a new Teacher, class or period,
the
stu_no would start at 1 again.

Basically counting and number each student for each
teacher, class, period.


-----Original Message-----
I don't think you can get a running total
without
an
ORDER BY. I didn't
notice an ORDER BY in your sample that matched
anything
that looked like a
running sum. I like puzzles but it would help
if
you
would describe the
pattern.

--
Duane Hookom
MS Access MVP


in
message
Is there any way in a query to do a running total
like
records?

the output that I am trying to acheive is this:

teacher class period student stu_no
Mr. A A 1 Joe 1
Mr. A A 1 Bob 2
Mr. A A 1 Jim 3
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

I have been trying everything with count but all I
can
acheive is a complete total - what I really need
is a
running total.

I would REALLY appreciate any help.
thank you in advance


.

.



.



.


.
 
I wish you had posted your sql. I expect you didn't get it correct yet. You
may need to start a new thread if no one responds to this. I am going out of
town for work for the next 10 days.

--
Duane Hookom
MS Access MVP


Maureen said:
Pardon me, for missing that.
I tried with the second select and
unfortunately this gives a total number of records.
The result is:

Teacher Class Period Student Stu_No
Mr. A A 1 Joe 159
Mr. A A 1 Joe 159
Mr. A A 1 Bob 159
Mr. A A 1 Jim 159
Mr. A A 2 Sue 159
Mr. A B 1 Jon 159

What I need is:
Teacher Class Period Student Stu_No
Mr. A A 1 Joe 1
Mr. A A 1 Joe 2
Mr. A A 1 Bob 3
Mr. A A 1 Jim 4
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

Can't this be done?
-----Original Message-----
Your query doesn't resemble mine suggestion. I had two "SELECT " in my query
versus your one. Try this:

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM DailySchedData A
WHERE A.Teacher = DailySchedData.Teacher
AND A.Class = DailySchedData.Class
AND A.Period = DailySchedData.Period
AND A.Student <= DailySchedData.Student) as Stu_No
FROM DailySchedData
ORDER BY Teacher, Class, Period, Student;

--
Duane Hookom
MS Access MVP
--

I am unable to make the query example that you gave me
work. I receive the message "You tried to execute a
query that does not include the specified
expression "Teacher" as part of an aggregate function."

it looks like this:
SELECT DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT, Count(*) AS STuNo
FROM DailySchedData INNER JOIN testA ON
(DailySchedData.Shift = testA.Shift) AND
(DailySchedData.PosNum = testA.PosNum)
AND (DailySchedData.Class = testA.Class)
AND (DailySchedData.TEACHER = testA.TEACHER)
WHERE (((testA.STUDENT)<=[DailySchedData]![STUDENT]))
ORDER BY DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT;

I know that the numbering would be easier at the report
level, if I could get away with that I would do it in a
second. However, I have to create a way to number the
students based on Teacher, Class, Period. - This numbers
corresponds to an already in-place schedule system.

Is there anything else that I can try?
Or to alter the query?

thank you for your help

-----Original Message-----
You need to add Student to the sort. Also, I asked if
this was going to a
report where the numbering would be much easier. The
following query assumes
your table name is tblA. Change all "tblA" to your table
or query name.

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM tblA A
WHERE A.Teacher = tblA.Teacher
AND A.Class = tblA.Class
AND A.Period = tblA.Period
AND A.Student <=tblA.Student) as Stu_No
FROM tblA
ORDER BY Teacher, Class, Period, Student;



--
Duane Hookom
MS Access MVP
--

message
I do need the counting to occur at either the query
level
or at the table level.

I am sorting by teacher, class, period > this is where
I
need to have the stu_no > to number each student that
falls into that section.

If it were feasible and a onetime thing - I would
create
several tables for each teacher, class, period and make
an autonumber for the stu_no - then just join them
together.

However, this data is always going to be changing as it
is a schedule.

I am REALLY stuck with this and don't know the way to
accomplish the output.

I would appreciate any help at all that you could
offer.

thank you
-----Original Message-----
All query designs allow sorting. Is this query going
into a report? If so,
you should do your counting there. If not, come on
back.

--
Duane Hookom
MS Access MVP


in
message
I was looking at the query and with a totals query
there
is no order by only group by.
-----Original Message-----
The order by is Teacher, class, period
each row that has a different student would cause
the
stu_no to increase by 1.
When the next row has a new Teacher, class or
period,
the
stu_no would start at 1 again.

Basically counting and number each student for each
teacher, class, period.


-----Original Message-----
I don't think you can get a running total without
an
ORDER BY. I didn't
notice an ORDER BY in your sample that matched
anything
that looked like a
running sum. I like puzzles but it would help if
you
would describe the
pattern.

--
Duane Hookom
MS Access MVP


"Maureen" <[email protected]>
wrote
in
message
Is there any way in a query to do a running
total
like
records?

the output that I am trying to acheive is this:

teacher class period student stu_no
Mr. A A 1 Joe 1
Mr. A A 1 Bob 2
Mr. A A 1 Jim 3
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

I have been trying everything with count but
all I
can
acheive is a complete total - what I really need
is a
running total.

I would REALLY appreciate any help.
thank you in advance


.

.



.



.


.
 
Thank you a million for all of your help.

This is my SQL :
SELECT TEACHER, Class, Period, Student
(SELECT Count(*) FROM testA, DailySchedData
WHERE testA.TEACHER=DailySchedData.TEACHER
AND testA.Class=DailySchedData.Class
AND testA.Period=DailySchedData.Period
AND testA.Student<>DailySchedData.Student;) AS Stu_No
FROM DailySchedData
ORDER BY TEACHER, Class, Period, Student;

I an working with 144 rows and my result is 153 for each
row.
It should work - I don't know why it doesn't...maybe
something with the tables.

thanks again
-----Original Message-----
I wish you had posted your sql. I expect you didn't get it correct yet. You
may need to start a new thread if no one responds to this. I am going out of
town for work for the next 10 days.

--
Duane Hookom
MS Access MVP


Pardon me, for missing that.
I tried with the second select and
unfortunately this gives a total number of records.
The result is:

Teacher Class Period Student Stu_No
Mr. A A 1 Joe 159
Mr. A A 1 Joe 159
Mr. A A 1 Bob 159
Mr. A A 1 Jim 159
Mr. A A 2 Sue 159
Mr. A B 1 Jon 159

What I need is:
Teacher Class Period Student Stu_No
Mr. A A 1 Joe 1
Mr. A A 1 Joe 2
Mr. A A 1 Bob 3
Mr. A A 1 Jim 4
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

Can't this be done?
-----Original Message-----
Your query doesn't resemble mine suggestion. I had two "SELECT " in my query
versus your one. Try this:

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM DailySchedData A
WHERE A.Teacher = DailySchedData.Teacher
AND A.Class = DailySchedData.Class
AND A.Period = DailySchedData.Period
AND A.Student <= DailySchedData.Student) as Stu_No
FROM DailySchedData
ORDER BY Teacher, Class, Period, Student;
in
message
I am unable to make the query example that you gave me
work. I receive the message "You tried to execute a
query that does not include the specified
expression "Teacher" as part of an aggregate function."

it looks like this:
SELECT DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT, Count(*) AS STuNo
FROM DailySchedData INNER JOIN testA ON
(DailySchedData.Shift = testA.Shift) AND
(DailySchedData.PosNum = testA.PosNum)
AND (DailySchedData.Class = testA.Class)
AND (DailySchedData.TEACHER = testA.TEACHER)
WHERE (((testA.STUDENT)<=[DailySchedData]! [STUDENT]))
ORDER BY DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT;

I know that the numbering would be easier at the report
level, if I could get away with that I would do it in a
second. However, I have to create a way to number the
students based on Teacher, Class, Period. - This numbers
corresponds to an already in-place schedule system.

Is there anything else that I can try?
Or to alter the query?

thank you for your help

-----Original Message-----
You need to add Student to the sort. Also, I asked if
this was going to a
report where the numbering would be much easier. The
following query assumes
your table name is tblA. Change all "tblA" to your table
or query name.

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM tblA A
WHERE A.Teacher = tblA.Teacher
AND A.Class = tblA.Class
AND A.Period = tblA.Period
AND A.Student <=tblA.Student) as Stu_No
FROM tblA
ORDER BY Teacher, Class, Period, Student;
wrote
in
message
I do need the counting to occur at either the query
level
or at the table level.

I am sorting by teacher, class, period > this is where
I
need to have the stu_no > to number each student that
falls into that section.

If it were feasible and a onetime thing - I would
create
several tables for each teacher, class, period
and
make
an autonumber for the stu_no - then just join them
together.

However, this data is always going to be changing as it
is a schedule.

I am REALLY stuck with this and don't know the
way
to
accomplish the output.

I would appreciate any help at all that you could
offer.

thank you
-----Original Message-----
All query designs allow sorting. Is this query going
into a report? If so,
you should do your counting there. If not, come on
back.

--
Duane Hookom
MS Access MVP


in
message
I was looking at the query and with a totals query
there
is no order by only group by.
-----Original Message-----
The order by is Teacher, class, period
each row that has a different student would cause
the
stu_no to increase by 1.
When the next row has a new Teacher, class or
period,
the
stu_no would start at 1 again.

Basically counting and number each student
for
each
teacher, class, period.


-----Original Message-----
I don't think you can get a running total without
an
ORDER BY. I didn't
notice an ORDER BY in your sample that matched
anything
that looked like a
running sum. I like puzzles but it would
help
if
you
would describe the
pattern.

--
Duane Hookom
MS Access MVP


"Maureen"
wrote
in
message
[email protected]...
Is there any way in a query to do a running
total
like
records?

the output that I am trying to acheive is this:

teacher class period student stu_no
Mr. A A 1 Joe 1
Mr. A A 1 Bob 2
Mr. A A 1 Jim 3
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

I have been trying everything with count but
all I
can
acheive is a complete total - what I
really
need
is a
running total.

I would REALLY appreciate any help.
thank you in advance


.

.



.



.



.


.
 
Try the following SQL statement

I think it takes care of your problems.

SELECT TEACHER, Class, Period, Student
(SELECT Count(*)
FROM DailySchedData AS TestA
WHERE testA.TEACHER=DailySchedData.TEACHER
AND testA.Class=DailySchedData.Class
AND testA.Period=DailySchedData.Period
AND testA.Student <= DailySchedData.Student) AS Stu_No
FROM DailySchedData
ORDER BY TEACHER, Class, Period, Student;
Thank you a million for all of your help.

This is my SQL :
SELECT TEACHER, Class, Period, Student
(SELECT Count(*) FROM testA, DailySchedData
WHERE testA.TEACHER=DailySchedData.TEACHER
AND testA.Class=DailySchedData.Class
AND testA.Period=DailySchedData.Period
AND testA.Student<>DailySchedData.Student;) AS Stu_No
FROM DailySchedData
ORDER BY TEACHER, Class, Period, Student;

I an working with 144 rows and my result is 153 for each
row.
It should work - I don't know why it doesn't...maybe
something with the tables.

thanks again
-----Original Message-----
I wish you had posted your sql. I expect you didn't get it correct yet. You
may need to start a new thread if no one responds to this. I am going out of
town for work for the next 10 days.

--
Duane Hookom
MS Access MVP


Pardon me, for missing that.
I tried with the second select and
unfortunately this gives a total number of records.
The result is:

Teacher Class Period Student Stu_No
Mr. A A 1 Joe 159
Mr. A A 1 Joe 159
Mr. A A 1 Bob 159
Mr. A A 1 Jim 159
Mr. A A 2 Sue 159
Mr. A B 1 Jon 159

What I need is:
Teacher Class Period Student Stu_No
Mr. A A 1 Joe 1
Mr. A A 1 Joe 2
Mr. A A 1 Bob 3
Mr. A A 1 Jim 4
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

Can't this be done?

-----Original Message-----
Your query doesn't resemble mine suggestion. I had
two "SELECT " in my query
versus your one. Try this:

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM DailySchedData A
WHERE A.Teacher = DailySchedData.Teacher
AND A.Class = DailySchedData.Class
AND A.Period = DailySchedData.Period
AND A.Student <= DailySchedData.Student) as Stu_No
FROM DailySchedData
ORDER BY Teacher, Class, Period, Student;

--
Duane Hookom
MS Access MVP
--

message
I am unable to make the query example that you gave me
work. I receive the message "You tried to execute a
query that does not include the specified
expression "Teacher" as part of an aggregate function."

it looks like this:
SELECT DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT, Count(*) AS STuNo
FROM DailySchedData INNER JOIN testA ON
(DailySchedData.Shift = testA.Shift) AND
(DailySchedData.PosNum = testA.PosNum)
AND (DailySchedData.Class = testA.Class)
AND (DailySchedData.TEACHER = testA.TEACHER)
WHERE (((testA.STUDENT)<=[DailySchedData]! [STUDENT]))
ORDER BY DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT;

I know that the numbering would be easier at the report
level, if I could get away with that I would do it in a
second. However, I have to create a way to number the
students based on Teacher, Class, Period. - This
numbers
corresponds to an already in-place schedule system.

Is there anything else that I can try?
Or to alter the query?

thank you for your help

-----Original Message-----
You need to add Student to the sort. Also, I asked if
this was going to a
report where the numbering would be much easier. The
following query assumes
your table name is tblA. Change all "tblA" to your
table
or query name.

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM tblA A
WHERE A.Teacher = tblA.Teacher
AND A.Class = tblA.Class
AND A.Period = tblA.Period
AND A.Student <=tblA.Student) as Stu_No
FROM tblA
ORDER BY Teacher, Class, Period, Student;



--
Duane Hookom
MS Access MVP
--

in
message
I do need the counting to occur at either the query
level
or at the table level.

I am sorting by teacher, class, period > this is
where
I
need to have the stu_no > to number each student
that
falls into that section.

If it were feasible and a onetime thing - I would
create
several tables for each teacher, class, period and
make
an autonumber for the stu_no - then just join them
together.

However, this data is always going to be changing
as it
is a schedule.

I am REALLY stuck with this and don't know the way
to
accomplish the output.

I would appreciate any help at all that you could
offer.

thank you
-----Original Message-----
All query designs allow sorting. Is this query
going
into a report? If so,
you should do your counting there. If not, come on
back.

--
Duane Hookom
MS Access MVP


"Maureen" <[email protected]>
wrote
in
message
I was looking at the query and with a totals
query
there
is no order by only group by.
-----Original Message-----
The order by is Teacher, class, period
each row that has a different student would
cause
the
stu_no to increase by 1.
When the next row has a new Teacher, class or
period,
the
stu_no would start at 1 again.

Basically counting and number each student for
each
teacher, class, period.


-----Original Message-----
I don't think you can get a running total
without
an
ORDER BY. I didn't
notice an ORDER BY in your sample that matched
anything
that looked like a
running sum. I like puzzles but it would help
if
you
would describe the
pattern.

--
Duane Hookom
MS Access MVP


"Maureen"
wrote
in
message
[email protected]...
Is there any way in a query to do a running
total
like
records?

the output that I am trying to acheive is
this:

teacher class period student stu_no
Mr. A A 1 Joe 1
Mr. A A 1 Bob 2
Mr. A A 1 Jim 3
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

I have been trying everything with count but
all I
can
acheive is a complete total - what I really
need
is a
running total.

I would REALLY appreciate any help.
thank you in advance


.

.



.



.



.


.
 
BRAVO!!! You are brilliant! And you have saved my
sanity!!!

I thank you a million!!
-----Original Message-----
Try the following SQL statement

I think it takes care of your problems.

SELECT TEACHER, Class, Period, Student
(SELECT Count(*)
FROM DailySchedData AS TestA
WHERE testA.TEACHER=DailySchedData.TEACHER
AND testA.Class=DailySchedData.Class
AND testA.Period=DailySchedData.Period
AND testA.Student <= DailySchedData.Student) AS Stu_No
FROM DailySchedData
ORDER BY TEACHER, Class, Period, Student;
Thank you a million for all of your help.

This is my SQL :
SELECT TEACHER, Class, Period, Student
(SELECT Count(*) FROM testA, DailySchedData
WHERE testA.TEACHER=DailySchedData.TEACHER
AND testA.Class=DailySchedData.Class
AND testA.Period=DailySchedData.Period
AND testA.Student<>DailySchedData.Student;) AS Stu_No
FROM DailySchedData
ORDER BY TEACHER, Class, Period, Student;

I an working with 144 rows and my result is 153 for each
row.
It should work - I don't know why it doesn't...maybe
something with the tables.

thanks again
-----Original Message-----
I wish you had posted your sql. I expect you didn't
get
it correct yet. You
may need to start a new thread if no one responds to this. I am going out of
town for work for the next 10 days.

--
Duane Hookom
MS Access MVP


"Maureen" <[email protected]> wrote
in
message
Pardon me, for missing that.
I tried with the second select and
unfortunately this gives a total number of records.
The result is:

Teacher Class Period Student Stu_No
Mr. A A 1 Joe 159
Mr. A A 1 Joe 159
Mr. A A 1 Bob 159
Mr. A A 1 Jim 159
Mr. A A 2 Sue 159
Mr. A B 1 Jon 159

What I need is:
Teacher Class Period Student Stu_No
Mr. A A 1 Joe 1
Mr. A A 1 Joe 2
Mr. A A 1 Bob 3
Mr. A A 1 Jim 4
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

Can't this be done?

-----Original Message-----
Your query doesn't resemble mine suggestion. I had
two "SELECT " in my query
versus your one. Try this:

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM DailySchedData A
WHERE A.Teacher = DailySchedData.Teacher
AND A.Class = DailySchedData.Class
AND A.Period = DailySchedData.Period
AND A.Student <= DailySchedData.Student) as Stu_No
FROM DailySchedData
ORDER BY Teacher, Class, Period, Student;
wrote
in
message
I am unable to make the query example that you
gave
me
work. I receive the message "You tried to execute a
query that does not include the specified
expression "Teacher" as part of an aggregate function."

it looks like this:
SELECT DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT, Count(*) AS STuNo
FROM DailySchedData INNER JOIN testA ON
(DailySchedData.Shift = testA.Shift) AND
(DailySchedData.PosNum = testA.PosNum)
AND (DailySchedData.Class = testA.Class)
AND (DailySchedData.TEACHER = testA.TEACHER)
WHERE (((testA.STUDENT)<=[DailySchedData]! [STUDENT]))
ORDER BY DailySchedData.TEACHER, DailySchedData.Class,
DailySchedData.Period, testA.STUDENT;

I know that the numbering would be easier at the report
level, if I could get away with that I would do
it
in a
second. However, I have to create a way to
number
the
students based on Teacher, Class, Period. - This
numbers
corresponds to an already in-place schedule system.

Is there anything else that I can try?
Or to alter the query?

thank you for your help

-----Original Message-----
You need to add Student to the sort. Also, I
asked
if
this was going to a
report where the numbering would be much easier. The
following query assumes
your table name is tblA. Change all "tblA" to your
table
or query name.

SELECT Teacher, Class, Period, Student,
(SELECT Count(*) FROM tblA A
WHERE A.Teacher = tblA.Teacher
AND A.Class = tblA.Class
AND A.Period = tblA.Period
AND A.Student <=tblA.Student) as Stu_No
FROM tblA
ORDER BY Teacher, Class, Period, Student;



--
Duane Hookom
MS Access MVP
--

in
message
I do need the counting to occur at either the query
level
or at the table level.

I am sorting by teacher, class, period > this is
where
I
need to have the stu_no > to number each student
that
falls into that section.

If it were feasible and a onetime thing - I would
create
several tables for each teacher, class, period and
make
an autonumber for the stu_no - then just join them
together.

However, this data is always going to be changing
as it
is a schedule.

I am REALLY stuck with this and don't know the way
to
accomplish the output.

I would appreciate any help at all that you could
offer.

thank you
-----Original Message-----
All query designs allow sorting. Is this query
going
into a report? If so,
you should do your counting there. If not,
come
on
back.

--
Duane Hookom
MS Access MVP


"Maureen"
wrote
in
message
[email protected]...
I was looking at the query and with a totals
query
there
is no order by only group by.
-----Original Message-----
The order by is Teacher, class, period
each row that has a different student would
cause
the
stu_no to increase by 1.
When the next row has a new Teacher, class or
period,
the
stu_no would start at 1 again.

Basically counting and number each student for
each
teacher, class, period.


-----Original Message-----
I don't think you can get a running total
without
an
ORDER BY. I didn't
notice an ORDER BY in your sample that matched
anything
that looked like a
running sum. I like puzzles but it would help
if
you
would describe the
pattern.

--
Duane Hookom
MS Access MVP


"Maureen"
[email protected]...
Is there any way in a query to do a running
total
like
records?

the output that I am trying to acheive is
this:

teacher class period student stu_no
Mr. A A 1 Joe 1
Mr. A A 1 Bob 2
Mr. A A 1 Jim 3
Mr. A A 2 Sue 1
Mr. A B 1 Jon 1

I have been trying everything with
count
but
all I
can
acheive is a complete total - what I really
need
is a
running total.

I would REALLY appreciate any help.
thank you in advance


.

.



.



.



.



.
.
 
Didn't do any more than Duane was doing. You helped by posting your SQL statement.

Glad it worked.
 
Back
Top