how to sum all of the count items in xquery - xquery

My problem is i want to display the count of all genre that is equals to actions
`
<videos genre="action" count="{
for $videos in doc("videos.xml")/result/videos/video
let $count := 0
where $videos/genre ="action"
return count($videos/genre)
}"
`
``
but my result is this
the count is=1 1 1 i want the answer is equal to 3
im expecting a result that is
<videos genre="action" count="3"><video>

You are making it a bit too complicated; try something like:
<videos genre="action" count="{
count(doc("videos.xml")//video[.//genre[.="action"]])
}"/>
or, depending on the struture of you actual videos file, you can use instead
count(//video[.//.="action"])
Those should get you your expected output.

Related

How to find the minimum value for 1-many relationship?

I want to find the minimum date value in a list of transactions that are associated with an investment. There are many transactions for one investment, clearly. How do I write this so that Progress will only give me the minimum transaction date? I get the minimum at the end of my list, but I do not want the list, just the minimum value.
FOR EACH ilinvest WHERE ilinvest.inv-num EQ 406885:
FOR EACH iltrans WHERE iltrans.reg-pin EQ ilinvest.reg-pin:
DISPLAY iltrans.tran-dt(MINIMUM).
END.
END.
If you have an index on the tran-dt field, you could do something like
FOR EACH ilinvest WHERE ilinvest.inv-num EQ 406885:
FOR EACH iltrans WHERE iltrans.reg-pin EQ ilinvest.reg-pin
BY iltrans.tran-dt ASCENDING:
// The iltrans.tran-dt value here is the lowest. Note that
// you may see the unknown value .
// Leave after getting the first record
LEAVE.
END.
END.
Thank you both for your help. Removing the ascending worked like a charm:
FOR EACH ilinvest:
FOR EACH iltrans WHERE iltrans.reg-pin EQ ilinvest.reg-pin
AND iltrans.acct-num EQ ilinvest.inv-num
BY iltrans.tran-dt:
iMin = iltrans.tran-dt.
LEAVE.
END.
END.
Beware if your date field has no value, ie the unknown value (?). If the unknown value sorts before or after other values depends on all sorts of black magic
Additionally, since I do not like leave, I prefer a while:
def var dt min as date no-undo.
for each ilinvest no-lock,
each iltrans
where iltrans.reg-pin = ilinvest.reg-pin
and iltrans.acct-num = ilinvest.inv-num
no-lock
by iltrans.tran-dt
while dtmin = ?:
if iltrans.trans-dt <> ? then
dtmin = iltrans.tran-dt.
end.

Doctrine 2 select entities with none or less than relations

I'm trying to find all rows with none or less than 3 relations. What would be the best approach for that?
I tried the following code with several different selects, having, joins but I can't figure out how to do it the right way:
$db = $this->createQueryBuilder('u');
$db->addSelect('COALESCE(COUNT(errors), 0) AS HIDDEN errorCount');
$db->join('u.errors', 'errors');
$db->where('u.field1 IS NULL AND u.field2 NOT LIKE \'\'');
$db->having('errorCount < 3');
Thank you very much in advance.
The COUNT function is an aggregate function which will return a single result unless you instruct it to group by something.
$db = $this->createQueryBuilder('u');
$db->addSelect('COUNT(errors) AS HIDDEN errorCount');
$db->leftJoin('u.errors', 'errors');
$db->where('u.field1 IS NULL AND u.field2 NOT LIKE \'\'');
$db->having('errorCount < 3');
$db->groupBy('u');
Additionally, if you want to count the number of relations that may or may not exist use a LEFT JOIN. The count on these results will be 0 which is < 3.

Format numeric values in Filemaker 12 List() result

I'm using List() to retrieve a numeric field which I subsequently display on a report view via a merge variable inside a text field. The data being displayed is a list of employees who worked on a particular job on a particular day, and the number of hours they worked under various classifications (normal, overtime, non-billable, non-billable overtime, et al). The hours are all calculated fields pulled from another table, but they need to be stored numerically.
Each column has its own text field:
| <<$$Name>> | <<$$normalHours>> | <<$$otHours>> | ...
Giving output such as:
Jim Jones 8 2
Ralph Ryder 4.25 0
Foo McBar 10 2.5
The field height needs to be dynamic because there could be anywhere from 1 to 10 or so employees displayed.
The issue is that I would like to always display the hours field with two decimal places:
Jim Jones 8.00 2.00
Ralph Ryder 4.25 0.00
Foo McBar 10.00 2.50
This is normally trivial via Inspector -> Data for a single-value field, and perhaps it still is trivial -- but I'm just not seeing it.
I've tried using SetPrecision(hours ; 2) when populating the field, and also (though I didn't think it would actually work) when creating my list variable:
$$normalHours = SetPrecision( List( laborTable::normalHours ) ; 2 )
In both cases I still see plain integer output for whole numbers and no trailing zeroes in any case.
Please let me know if I can provide any further information that might help.
A few things you can try:
Auto-enter calculation replacing existing value
You could change your normalHours field to be an auto-enter calculation, uncheck 'do not replace existing value', and set the calculation to the following:
Let ( [
whole = Int ( Self ) ;
remainder = Abs ( Self ) - Abs ( whole )
] ;
Case ( remainder = 0 ;
whole & ".00" ;
Self )
)
This will append a ".00" to any whole numbers in your field. This should then come through your List() function later.
New calculation field
Alternately, if you don't want to automatically modify the existing number, you could make a new calculation field with a very similar calculation:
Let ( [
whole = Int ( normalHours ) ;
remainder = Abs ( normalHours ) - Abs ( whole )
] ;
Case ( remainder = 0 ;
whole & ".00" ;
normalHours )
)
And then you would use that calculation field in the List function, instead of your normalHours field.
For more complicated field formatting, you could also use a custom function like this: http://www.briandunning.com/cf/945
Can you replace this with a portal, perhaps?
If not, then try to set formatting on the merge text field itself. It can have formatting too; only one variant for each data type, but in your case it should be enough.

MDX - distinct count

I was following this article:
http://msdn.microsoft.com/en-us/library/aa902637%28v=sql.80%29.aspx
and my query for distinct count looks like this:
Count(CrossJoin({[Measures].[Submission Count]}, [Submission].[PK Submission].Members), ExcludeEmpty)
it returns always 1 more than it should (for example it returns 27 instead of 26).
In the same article there is this query (which is suppose to solve this problem):
Count(CrossJoin( {[Sales]},
Descendants([Customers].CurrentMember, [Customer Names])),
ExcludeEmpty)
But I can't get it to work. I've tried these two but second one always returns 1 or 0 while the first one doesn't work (error: I have to explicitly define a level):
Count(CrossJoin( {[Measures].[Submission Count]},
Descendants([Submission].CurrentMember, [Submission].[PK Submission])),
ExcludeEmpty)
Count(CrossJoin( {[Measures].[Submission Count]},
Descendants([Submission].[PK Submission].CurrentMember, [Submission].[PK Submission])),
ExcludeEmpty)
Any idea what am I doing wrong?
Thanks!
The reason the first query returns "1 more than it should" is because the [Submission].[PK Submission].Members tuple set also includes the All member.
If you refer to the [PK Submission] level instead of all the members of the [PK Submission] hierarchy, it doesn't include the All member.
So, the following returns what you're expecting:
Count( CrossJoin( { [Measures].[Submission Count] }
, { [Submission].[PK Submission].[PK Submission] })
, ExcludeEmpty)

Display number of rows in a Drupal View

How can I display the total number of rows shown in a Drupal view as well as the number of rows out of the total currently being shown?
print $GLOBALS['current_view']->total_rows; does not work
This question might be of help
$view->total_rows is wrong (sort of), I want "Items to display"
$view = views_get_view('MY_VIEW_NAME');
$view->set_display('MY_DISPLAY'); // like 'block_1'
$view->render();
print sizeof($view->result);
print sizeof($view->result);
does not work, because it returns the number of rows, not the number of total results. So if you have a pager, this doesn't work. You'll need
print $view->total_rows;
Another, even better solution would be to implement hook_views_pre_render()
function MYMODULE_views_pre_render(&$view) {
if ($view->name == 'MY_VIEW') {
$view->set_title(t('Search (#count results)', array('#count' => $view->total_rows > 0 ? $view->total_rows : 'No')));
}
}

Resources