Matrix report [message #605620] |
Sun, 12 January 2014 06:27 |
shahzad-ul-hasan
Messages: 639 Registered: August 2002
|
Senior Member |
|
|
Dear
i want to display all dates(heading) according to months in matrix style report. and fill the all column with p and A. but in this report which is attached some columns are blank please advised how i can correct this problem..
|
|
|
|
Re: Matrix report [message #605634 is a reply to message #605632] |
Sun, 12 January 2014 21:35 |
shahzad-ul-hasan
Messages: 639 Registered: August 2002
|
Senior Member |
|
|
05, 21, 22,29, 30 is the days of month and the student present in those days will be (P). the students which is not present in those days autometically assign (A). But when i run this query is will shows the result which i attached.
SELECT DISTINCT max(substr(inout.dated,1,2)) dat, student.stuid, max(intime) intime,student.name
FROM student,inout
WHERE student.stuId= inout.stuID(+)
group by student.stuid,NAME
order by stuid
Student is Master table and inout is detail table.
|
|
|
|
|
|
|
|
Re: Matrix report [message #605650 is a reply to message #605649] |
Mon, 13 January 2014 02:24 |
shahzad-ul-hasan
Messages: 639 Registered: August 2002
|
Senior Member |
|
|
intime is the attendance time of the student on distinct date. please check that main query;
SELECT DISTINCT max(substr(inout.dated,1,2)) dat, student.stuID, max(intime) intime,student.name
FROM STUdent,inout
WHERE student.stuId= inout.stuID(+)
group by student.stuid,NAME
order by stuid
please check that main query.
the code you have send is the showing nothing.....why the file is not attached... i have uploded.
[Updated on: Mon, 13 January 2014 02:27] Report message to a moderator
|
|
|
|
Re: Matrix report [message #605652 is a reply to message #605651] |
Mon, 13 January 2014 02:34 |
shahzad-ul-hasan
Messages: 639 Registered: August 2002
|
Senior Member |
|
|
attached table structure...
SQL> desc student
Name Null? Type
----------------------------------------- -------- ----------------------------
STUID NOT NULL NUMBER(8)
STATUS VARCHAR2(30)
CLASS VARCHAR2(25)
SECTION VARCHAR2(30)
SESION VARCHAR2(30)
ROLLNO NUMBER(4)
ADM_NO NUMBER(7)
STUDENTID VARCHAR2(15)
NAME VARCHAR2(250)
F_NAME VARCHAR2(250)
MNAME VARCHAR2(250)
GENDER VARCHAR2(15)
FCNIC VARCHAR2(25)
MCNIC VARCHAR2(25)
MOB VARCHAR2(20)
RES_PH VARCHAR2(20)
ADDRES VARCHAR2(450)
PROFESSION VARCHAR2(120)
DOA DATE
DOB DATE
PRVSCHOOL VARCHAR2(100)
PRVCLASS VARCHAR2(30)
LEAV_DATE DATE
BOARD VARCHAR2(100)
GRUP VARCHAR2(50)
BRDREGNO VARCHAR2(35)
GURD_NAME VARCHAR2(250)
GMOBILE VARCHAR2(20)
TUITION NUMBER(5)
TRNID NUMBER(4)
TRANSP NUMBER(6)
COMENT VARCHAR2(130)
BAYFORM VARCHAR2(25)
ADM_CLAS VARCHAR2(30)
BRDROLL NUMBER(11)
CONS_TYPE VARCHAR2(60)
MOB1 VARCHAR2(25)
COMENT1 VARCHAR2(300)
RELIGION VARCHAR2(50)
--------------------------
SQL> desc inout;
Name Null? Type
----------------------------------------- -------- ----------------------
STUID NUMBER(8)
INTIME VARCHAR2(60)
OTIME VARCHAR2(60)
DATED DATE
[Updated on: Mon, 13 January 2014 02:34] Report message to a moderator
|
|
|
Re: Matrix report [message #605655 is a reply to message #605652] |
Mon, 13 January 2014 02:55 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
SELECT DISTINCT max(substr(inout.dated,1,2)) dat, student.stuID, max(intime) intime,student.name
FROM STUdent,inout
WHERE student.stuId= inout.stuID(+)
group by student.stuid,NAME
order by stuid
This query is fundamentally flawed in a few ways:
1) It'll only give at most one record per student.
2) The returned intime may belong to a different record to the returned dated
3) You're relying on the default date format to get the day of the month.
If you've got a function that must return a value (and a simple if/else must) and you're still getting nulls that must mean the function isn't always getting run.
It's not getting run becuase of issue 1.
You need to join the students table to a calender query that will return all the dates you are interested in, e.g.
SELECT trunc(sysdate, 'MON') + rownum FROM dual connect by level < 31
Issue 3 can be fixed by using to_char instead of substr.
|
|
|
|
Re: Matrix report [message #605673 is a reply to message #605664] |
Mon, 13 January 2014 06:11 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
What do you think my post is if it's not advise?
If there's something you don't understand you need to say what.
If you have further questions you need to ask them.
|
|
|
|
|
|
Re: Matrix report [message #605681 is a reply to message #605680] |
Mon, 13 January 2014 08:41 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
I gave you a general suggestion for changing the query not actual code.
So I have no idea what you changed the query to.
It's really hard to help if you don't tell us what you've actually done.
|
|
|
Re: Matrix report [message #605682 is a reply to message #605681] |
Mon, 13 January 2014 08:45 |
shahzad-ul-hasan
Messages: 639 Registered: August 2002
|
Senior Member |
|
|
select max(to_char(dated,'DD')) dat,count(intime),student.stuid,student.name
from inout, student
where student.stuid=inout.stuid(+)
group by student.stuid,name
order by student.stuid
|
|
|
Re: Matrix report [message #605684 is a reply to message #605655] |
Mon, 13 January 2014 09:07 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
cookiemonster wrote on Mon, 13 January 2014 08:55You need to join the students table to a calender query that will return all the dates you are interested in, e.g.
SELECT trunc(sysdate, 'MON') + rownum FROM dual connect by level < 31
[Updated on: Mon, 13 January 2014 09:07] Report message to a moderator
|
|
|
|
|
Re: Matrix report [message #605760 is a reply to message #605728] |
Tue, 14 January 2014 07:23 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Littlefoot wrote on Tue, 14 January 2014 05:48The way I understood it, I think that the problem isn't "how to display all dates in a month" (i.e. how to fetch those that are missing, i.e. calendar-type query), but how to display A or P for a certain person on a certain date.
Of course, I might be wrong.
OP wants there to be an A or P for every single student for every single relevant date. Unless matrix reports do something I don't know about to fill in the gaps (possible) he needs a query that returns a row per student per relevant date. The blanks in the output will be where there is no intime record for that student for that date.
@shahzad-ul-hasan - This can be done in a single query. As LF says get something working in sqlplus - a query that outputs one row per stundent per date and indicates if they're present or absent - you can then put that query in the matrix report and it should just work.
|
|
|
|
Re: Matrix report [message #605775 is a reply to message #605767] |
Tue, 14 January 2014 08:28 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
It may run in sqlplus but I guarantee it doesn't give one row per student per date.
The number of rows the query needs to return = number of students x number of dates you want to display.
inout doesn't contain one row per student per date you want to display does it? It's missing rows for some students for some dates, presumably the dates the students didn't attend.
As previously stated you need to join this query to a select that gets all the dates you are interested in.
Simple example
SQL> CREATE TABLE emp AS SELECT ROWNUM ID FROM dual CONNECT BY LEVEL < 4;
Table created
SQL> select * from emp;
ID
----------
1
2
3
SQL> --now a query to get some dates
SQL> SELECT trunc(SYSDATE) + ROWNUM FROM dual CONNECT BY LEVEL < 5;
TRUNC(SYSDATE)+ROWNUM
---------------------
15/01/2014
16/01/2014
17/01/2014
18/01/2014
SQL> --join the two
SQL>
SQL> WITH cal AS (SELECT trunc(SYSDATE) + ROWNUM dat FROM dual CONNECT BY LEVEL < 5)
2 SELECT ID, dat
3 FROM emp, cal
4 ORDER BY 1,2;
ID DAT
---------- -----------
1 15/01/2014
1 16/01/2014
1 17/01/2014
1 18/01/2014
2 15/01/2014
2 16/01/2014
2 17/01/2014
2 18/01/2014
3 15/01/2014
3 16/01/2014
3 17/01/2014
3 18/01/2014
12 rows selected
SQL>
Once you've got a query that gets one row per student per date you then need to outer join inout to it to see if the student was present on a given date.
|
|
|
|
|
|
Re: Matrix report [message #605911 is a reply to message #605899] |
Thu, 16 January 2014 04:14 |
shahzad-ul-hasan
Messages: 639 Registered: August 2002
|
Senior Member |
|
|
SQL*Plus: Release 9.2.0.1.0 - Production on Thu Jan 16 15:13:43 2014
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
|
|
|
|
|
|
|
|