Adding "All" option to a prompt Pentaho dashboard? - pentaho

I added a prompt in pentaho dashboard. And I want to add 'ALL' category to that prompt which means when I select "ALL", it shouldn't filter data, it should get all the data under the selected category. Could you guys please help me?

For that use the Type SQL List and "All" as value (Take care to case sensitive). An example Query would be:
SELECT DISTINCT 'All' AS VAL, 'ALL TERRITORIES' AS DESC FROM customer_w_ter
UNION ALL
select DISTINCT TERRITORY, TERRITORY from customer_w_ter

#Michael Christopher
I used following postgresql query to get the data.
select 'All' as accountclass
,status
,count(guaccountid) as count
from sms_accountinformation
group by status
union
select distinct accountclass
,status
,count(guaccountid)as count
from sms_accountinformation
group by accountclass,status
order by accountclass,status
Is there any alternatives without hardcoding?
data set looks like as follows
"All";"Active";2288
"All";"PD";257
"All";"TD";777
"Customer";"Active";2275
"Customer";"PD";152
"Customer";"TD";359
"Dealer";"Active";13
"Dealer";"PD";105
"Dealer";"TD";418

What you need to do in your query is to add an extra row with "ALL" data. Its not required to do a group by clause when writing the query for the ALL section. Check the below code (hope it will be clearer):
select distinct
accountclass,
status,
count(guaccountid)as count
from sms_accountinformation
group by accountclass,status order by accountclass,status
union
select 'ALL' as accountclass,
'ALL' as status,
'ALL' as count
from sms_accountinformation
This will fetch you a result set with 'ALL' as one more row which you can use it in your filter list.
Hope it helps:)

Related

SQL Sum Total with multiple assignments

select dc_id, whse_id, assg_id, START_DTIM,
UNIT_SHIP_CSE*prod_cub as TOTAL_CUBE
from exehoust.aseld
I attached a photo to show how the query currently populates. I want to sum the TOTAL_CUBE for each distinct ASSG_ID. I have tried case where sum and group by but keep failing. Basically want to do a SUM IF for each distinct ASSG_ID
You need to group by the assg_id, but ou need also the define what happens to all the other columns i choose MIN only to give you a hint, you need to choose the function yourself
select MIN(dc_id), MIN(whse_id), assg_id, MIN(START_DTIM),
SUM(UNIT_SHIP_CSE*prod_cub) as TOTAL_CUBE
from exehoust.aseld
GROUP BY assg_id
use select assg_id, sum() over(partition by assg_id order by assg_id) to sum by groupings

SQL: Group by Case Statement to sum Row Values

I have a table that looks like below. I am trying to group by subject using a case statement for every "subject" that starts with "cf" like something like the following:
SELECT CASE WHEN subject LIKE '%cf' THEN sum(Count)
FROM table
The goal is to just drop all the extra characters following "cf" and then sum the total count and create a new row as 'Cf' with the sum of count value as shown in the desired output.
subject. count
status 2461193
priority 1042073
ta. 126295
dueDate 62560
assignee 34142
cf2122 1
cf2123. 1
cf4312. 1
cf3234. 1
cf5464. 1
desired output:
subject. count
status 2461193
priority 1042073
ta. 126295
dueDate 62560
assignee 34142
cf. 1221
You want a GROUP BY based on an expression. You also need to put the wildcard for the LIKE condition after the prefix you want, 'cf%'
SELECT CASE
WHEN subject LIKE 'cf%' THEN 'cf'
else subject
end as normalized_subject,
sum("count")
FROM the_table
group by normalized_subject
order by sum("count") desc
Using a column alias in the GROUP BY is a Postgres extension to the SQL language. In other DBMS products you would need to repeat the CASE expression in the GROUP BY (which is only more to type, but won't change performance)
Online example

Not contained in eaggregate function/ the GROUP BY AND max date does not show the latest date

I am stucked here and your help will be appreciated. Based on the code that you see below:
I have a sub query with some conditions. especifically, the following:
AND OwnedByTeamJ='C - O Review'
AND OwnedByTeamJ is null
I want to get the results from the subquery,
Do another select on them because all I want is the latest date listed the table. As you can see in the picture, I want to be able to extract row#3 which has the highest date and its own by the team which is null (I guess! since there is no value there).
Now the problems:
1-at first the code worked and I saw all the records! though, it didsn't pick the latest date
2- sudennly it stopped working and saw this error:
Column 'tt.IncidentID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
select
distinct max(LastModifiedDateTimeJ),
incidentID,
EffecRequestStatus,
OwnedByTeamJ
From (
select
EffecRequestStatus,
IncidentID,
LastModifiedDateTimeJ,
OwnedByTeamJ,
DetailsJ,
Status,
OwnedByTeam
from IncidentView
where
CAST(CreatedDateTime as DATE) >='05-01-2019'
AND JournalTypeName like '%Journal - Note%'
AND OwnedByTeamJ='C - O Review'
AND OwnedByTeamJ is null
group by
EffecRequestStatus,
IncidentID,
LastModifiedDateTimeJ,
OwnedByTeamJ,
DetailsJ,
Status,
OwnedByTeam
) as tt
where
tt. RequestStatus not in ('Submission','P-C submission','C Review')
A sample of data look like the following but my table has more columns than that is listed here:
1) These conditions should not coexist:
AND OwnedByTeamJ='C - O Review'
AND OwnedByTeamJ is null
...because these two things are never true at the same time, and you will get an empty result-set. I guess what you want is
AND (OwnedByTeamJ='C - O Review' or OwnedByTeamJ is null)
2) The error you mention does not seem to agree with the query you've shown us. Did you try to make another group by externally?
3) It doesn't make sense to use distinct together with any aggregation function like max,sum, count etc.
4) As long as you have included EffecRequestStatus within the group by, you will get 3 rows, not 1, because all 3 rows have a different value for EffecRequestStatus. You will have to remove it from the group by, and therefore from the select as well, if you only want to see one row.
Try this, if you want to have a not empty result:
AND (OwnedByTeamJ='C - O Review'
OR OwnedByTeamJ is null)

How to compare ordered datasets with the dataset before?

I have the following query:
select * from events order by Source, DateReceived
This gives me something like this:
I would like to get the results which i marked blue -> When there are two or more equal ErrorNr-Entries behind each other FROM THE SAME SOURCE.
So I have to compare every row with the row before. How can I achieve that?
This is what I want to get:
Apply the row number over partition by option on your table:
SELECT
ROW_NUMBER() OVER(PARTITION BY Source ORDER BY datereceived)
AS Row,
* FROM events
Either you can run a (max) having > 1 option on the result set's row number. Or if you need the details, apply the same query deducting the row nuber with 1.
Then you can make a join on the source and the row numbers and if the error nr is the same then you have a hit.
You can use the partition by as below.
select * from(select
*,row_number()over(partition by source,errornr order by Source, DateReceived) r
from
[yourtable])t
where r>1
You can specify your column names in the outer select.

JSP result set from MS Access - how to get the location name?

I have a table called "form" in ms access which have following fields:
formno, location, status.
I want to create a report which calculates:
the total no of forms(columns) at each location
the total no of forms(columns) with status= "pending" at each location.
I tried to do it with this query:
select count(formno) as totalforms
from form
group by location;
select count(formno) as pendingforms
from form
group by location
WHERE status = 'pending';
SELECT Location, COUNT(FormNo) AS TotalForms,
SUM(IIF(status = "pending", 1, 0)) AS Pending
FROM FORM GROUP BY Location
Does this help?
The second SQL Statment has the Where Clause in the wrong place. It should look like one of these:
SELECT Count(form.formno) AS CountOfformno, form.location
FROM form
GROUP BY form.location, form.status
HAVING (((form.status)='pending'));
SELECT Count(form.formno) AS CountOfformno, form.location
FROM form
WHERE (((form.status)='pending'))
GROUP BY form.location;
Basically if you wish to group by a column and set criteria on it use the Having Clause. The Where Clause comes before the group by clause.
To learn the SQL syntax you may find it easier to use the Query By Design Grid (in Design View) first then switch to SQL View after you get the results you are after in Datasheet View.
Form is a reserved word and must be enclosed in square brackets: http://support.microsoft.com/kb/286335. I would suggest renaming the table, because it will continue to cause problems.
select location,count(formno) as totalforms
from [form]
group by location
select location, count(formno) as pendingforms
from [form]
WHERE status = 'pending'
group by location
Note that count(*) can also be used if you wish to include all records in the table: In SQL is there a difference between count(*) and count(<fieldname>)