Excel/Pentaho double group by + count - sql

I am having some problems dealing with Excel and pentaho (I guess due to my 0 experience with these tools...).
Having the following data set:
Interaction date interaction_name
21/08/13 course view
21/08/13 course view
21/08/13 forum view forum
21/08/13 course view
21/08/13 course view
21/08/13 course view
22/08/13 forum view forum
22/08/13 course view
22/08/13 forum view forum
22/08/13 user view all
22/08/13 user view
22/08/13 blog view
22/08/13 user view all
I would like to represent that on the 21/08/2013 there has been 4 course views and 1 forum view, on 22/08/2013 2 forum views, 1 course view, 3 user view all... and so on.
That is (from the SQL perspective) kind of a count in a double group by. First group by date, then group by interaction and count them. The correct SQL query could also help me.
I just cant figure out how to make it. I tried with excel and with pentaho, but seems that I am missing something...
Any help would be really apreciated! Thanks
My report in pentaho so far: Already tried with aggregation count, but it counts every interaction, without making any difference among them.

As #Marcus Rickert asked, you didn't specified data source, but I will suppose that is some SQL like database because you asked for right SQL query.
This one:
SELECT Interaction_date, Interaction_name, count(Interaction_name) from your_table group by Interaction_date,Interaction_name order by Interaction_date asc;
It will produce:
Interaction_date Interaction_name count
---------------------------------------------
21/08/13 course view 5
21/08/13 forum view forum 1
22/08/13 forum view forum 2
22/08/13 course view 1
22/08/13 user view all 2
22/08/13 user view 1
22/08/13 blog view 1
Now, you can put it in Pentaho Report Designer and group by (inside Report Designer) by Interaction_date.

Related

Filtering access control data to get list of people inside office

I would like to create an SQL query for a "Role Call" which would show me the people who are inside the building only. Each person has his own access card and has to go in or out of the building using 1 of 4 turnstiles. So far I managed to retrieve the 4 turnstiles (in and out) data for todays date. I need to filter the list to only show people who had an "in" entry but did not leave yet. People can come and go as they please and use any of the 4 turnstiles and have multiple "ins" and "outs" per day.
I am bit stuck here how to do this.
I am joining 2 tables which have the device information (turnstiles) and the log of all swiped cards. I am filtering for the turnstiles data only and todays date.
SELECT [dbo].[lACLog].[LogID],[dbo].[lACLog].[LogDate],[dbo].[lACLog].[DeviceAddress],[dbo].[pPeriphery].[Name],[dbo].[pPeriphery].[PeripheryUID],
[dbo].[lACLog].[CardNr],[dbo].[lACLog].[Name],[dbo].[lACLog].[PersonalNr],[dbo].[lACLog].[PersID]
FROM [dbo].[lACLog]
LEFT JOIN [dbo].[pPeriphery]
ON [dbo].[lACLog].[DeviceAddress]=[dbo].[pPeriphery].[DeviceAddress]
WHERE [dbo].[lACLog].[LogDate]>=CAST(GETDATE()AS Date) AND [dbo].[pPeriphery].[PeripheryUID]
IN ('2130B72E-D8E9-4269-B6B0-68BEC95CB483',
'9229D4B6-5CD7-43E6-B7C7-BF9779333521',
'919C5D57-5885-460A-8679-D0C257837D82',
'C45B8C65-FF46-42FA-B428-E01853DEB65E',
'550669EC-2BC4-4008-A1A7-469E9C5266C5',
'3C843DFA-CFE3-4E01-93E9-ADE50A2D5BED',
'FB6736AA-2940-497F-A367-5BB0308F4B77',
'E6EE768E-1587-41EF-B7FD-B61A14BA9395');

Oracle Application Express SQL Query to show meaningful information

I am trying to write a query that 1) works and 2) shows meaningful information.
However, I can't seem to complete both scenarios. Both bits of code do work to a degree. My SQL query does work by showing all the useful information a user wants but when you click the edit button it doesn't link properly so it won't allow the user to update that row. The other shows only keys and rowid but when you click edit does show the information and allows it to be updated.
So as not to get another down-voted question, I have taken pictures of each scenario to show the problem, but, ultimately, I need to show meaningful information: an id or key isn't meaningful to the vast majority of users.
Here is my code
SELECT APPLICATIONS.APP_ID, APPLICATIONS.SRN, STUDENTS.SURNAME, STUDENTS.FORENAME, APP_STATUS.STATUS, METHODS.METHOD, JOBS.JOB_TITLE, APPLICATIONS.APP_DATE
FROM APPLICATIONS
JOIN STUDENTS
ON APPLICATIONS.SRN = STUDENTS.SRN
JOIN APP_STATUS
ON APPLICATIONS.STATUS_ID = APP_STATUS.STATUS_ID
JOIN METHODS
ON APPLICATIONS.METHOD_ID = METHODS.METHOD_ID
JOIN JOBS
ON APPLICATIONS.JOB_ID = JOBS.JOB_ID;
and here are the pictures of it in action
below is the code that does not show meaningful information but does work.
select "ROWID",
"APP_ID",
"SRN",
"STATUS_ID",
"METHOD_ID",
"JOB_ID",
"APP_DATE"
from "#OWNER#"."APPLICATIONS"
If i knew how to properly use rowid i am sure this is a simple feat but i dont so if i could get any help it would be useful
//edit
who ever renamed this to Application Expression why? what i am using is Apex Application Express it was relevant information that got changed to something wrong which might make it hard for someone with a similar problem to find later.
In the second, simple query, apex can determine which table (and record) you are trying to edit.
In the first query, with the joins, it can't tell which of the five tables in query you want to edit. You probably want to have the edit link pass the primary key of the row from APPLICATIONS to the child page. You would need to build into that page any logic (lists of values etc) that map lookup tables (such as status) to the values needed in the APPLICATIONS table.

how to display two modles in a view and also attach a radio button group to each

Ok I have a database called survey just for testing purposes I have two tables Likert’s and questions within the likert table the following row are present Likert_ID ,Likert_ Description in the questions table I have the following rows question_ID and question_Description I’m using MVC and entity frame work 4 and also sql server 2014 the problem I’m having is displaying both models in a view and attaching a radio button group to each question based on the Likert_Description

SQL joins with views

I have a view that is now joining two other views with some extra tables.
It's very slow.
My experience tell me it's because views are not indexed by default. I tried to create an index on each of them, but it's not possible since they have self joins or inner queries.
My question is:
It appears to me that in general the join of views is not recommended. So, in short, there is no way to reuse a code from one view into another? Example: the view A calculates the percentage and the view B calculates something else that uses the percentage from view A plus other information from other tables/views. What would be the best approach? Do you really have to replicate the code from view A to view B so it uses the original table's indexes?
Views (simplified view, to show the issue):
View A (calculates the percentage):
SELECT dbo.tblPopAgeGrp.RevID, dbo.tblPopAgeGrp.VarID, dbo.tblPopAgeGrp.LocID,
dbo.tblPopAgeGrp.TimeID, dbo.tblPopAgeGrp.AgeID, tPAGT.AgeID AS AgeTotal,
100 * dbo.tblPopAgeGrp.PopMale / tPAGT.PopMale AS PopMalePerc,
100 * dbo.tblPopAgeGrp.PopFemale / tPAGT.PopFemale AS PopFemalePerc,
100 * dbo.tblPopAgeGrp.PopTotal / tPAGT.PopTotal AS PopTotalPerc
FROM dbo.tblPopAgeGrp
INNER JOIN dbo.tblPopAgeGrp tPAGT
ON dbo.tblPopAgeGrp.GroupID = tPAGT.GroupID
AND dbo.tblPopAgeGrp.AgeID = 700
View A by itself, since there so many records, takes a long time to execute. However, in view B the records are filtered according to the VersionID.
View B (gets the percentage from view A with additional info from another view):
SELECT vPAGP.VersionID,
vPAGP.LocationID AS LocID,
vPAGP.PopTotalPerc AS pPopTot,
vPAGP.PopMalePerc AS pMale,
vPAGP.PopFemalePerc AS pFemale,
vPAGPSR.PopMaleSexRatio AS SexRatio,
vPAGPSR.PopFemaleSexRatio AS FemRatio
FROM dbo.vwA AS vPAGP
INNER JOIN dbo.vwOther AS vPAGPSR
ON vPAGPSR.GroupID = vPAGP.GroupID
WHERE vPAGP.VersionID=10
Executing View A without filters, takes like 10 minutes. Executing it for VersionID=10 only, it executes in 10 seconds. The view vwOther executes very quickly.
Thanks!
You are not correct when you state "It appears to me that in general the join of views is not recommended."
Views can be combined with other views and will perform well provided that all JOINs are optimizable and have the appropriate index created and any filtering done within the view is optimizable and has appropriate indexes created.
A view based on other views should perform as well as the same query written to factor out the views. If you want further help, please post the definition of all views involved in your problem.

Values between pages with Apex

I tried looking for an answer, but everything I found seemed too high level. I am a college student who's working on a database project. We need to use apex (oracle) to shred data from an open API source. You can see what me & my team are working on here: http://bit.ly/Jvt4av.
I have listing of movies with links. Those links go to another page that is supposed to show all sorts of details for that movie.
I have successfully passed the movie_id variable between the list and the detail page, but I am stumped now. I need to show the movie's details and I don't want to use reports or forms because they're too ugly to show this kind of info. I want to be able to show the data with HTML. So, my questions are:
Where/how do I query the database, so I can use the results in HTML?
How do I display those results in HTML?
Thank you!
Well, if you have the movie ID then you can use it to query the database and get all the other details from the database. If you want to render those details using just plain HTML then a PL/SQL region in conjunction with some htp.p calls will do the job. For example:
for x in (select * from movies_details where id=<MOVIE_ID>) loop
htp.p('<h1>' || x.movie_title || '</h1>');
end loop