I have the given XML file (https://prod-c2g.s3.amazonaws.com/db/Winter2013/files/courses-noID.xml) and am attempting to do the following:
Return the number (count) of courses that have no lecturers as instructors.
I've tried
let $course := doc("courses.xml")//Course
return count($course/Instructors/not(Lecturer))
But instead of returning the number 10 it's returning 13. Because it's basically giving me a count of
false false false true true true true true true true true true true
Is there an additional check I need to do to limit the true's ?
Your test needs to be in a predicate.
Try this:
let $course := doc("courses.xml")//Course
return count($course/Instructors[not(Lecturer)])
Also, if you're truly trying to count courses, your count should actually be:
count($course[Instructors[not(Lecturer)]])
Related
I need to create a new column in my dataset (duplicate_name) that contains TRUE if there are more than one record for someone or FALSE otherwise. I found this code (I am working with sqlite):
SELECT *,
CASE
WHEN ROW NUMBER() OVER (PARTITION BY
first_name, last_name) > 1) THEN 'TRUE'
ELSE 'FALSE'
END AS duplicate_name
FROM users;
But when I ran it it gives me something like this (ONLY THE SECOND RECORD IS MARKED AS TRUE):
Carlo Thomas male FALSE
Carlo Thomas male TRUE
Don Scallion male FALSE
Tania Lopes female FALSE
What I need is a table like this (both records with the same name are marked as TRUE):
Carlo Thomas male TRUE
Carlo Thomas male TRUE
Don Scallion male FALSE
Tania Lopes female FALSE
Can someone help me, please.
Thanks
Instead of ROW_NUMBER() use COUNT(*) window function:
SELECT *,
CASE WHEN COUNT(*) OVER (PARTITION BY first_name, last_name) > 1 THEN 'TRUE' ELSE 'FALSE' END AS duplicate_name
FROM users;
or simpler with a 1 for true and 0 for false:
SELECT *,
COUNT(*) OVER (PARTITION BY first_name, last_name) > 1 AS duplicate_name
FROM users;
*where (citiStatus NOT IN ('Paid Off' ,'PAID-O'))
and (
revolver = 0
and (
(commitmentDate = '')
or (
(commitmentDate != '')
and (#currentDate < DATEADD(day, #noofDays, commitmentDate))
)
)
) // until here should verify with where condition . even if it is failed or not should execute next statement .
and (citiStatus NOT IN ('CANCELLED','Cancelled/Dead') or #currentMonth = MONTH(statusModifiedDate))-- this is will if above AND condition fails even if its true(but this should execute even to filter data).*
You need to have in mind two simple rules, the Associativity of Logical Operators is always from left to right, and the correct use of Parentheses having in consideration the logic of your problem for example:
select case when 1=1 and 1=2 or 3=3 then 1 else 0 end as result from dual;--result 1
First we evaluate 3=3 TRUE -> 1=2 FALSE -> evaluate OR OPERATOR (TRUE OR FALSE)-> TRUE
Second 1=1 TRUE -> evaluate AND OPERATOR -> TRUE AND TRUE -> TRUE
IF TRUE THEN 1
My advice is always to use Parentheses, in this way you will evaluate the whole expression and no token by token for example
select case when ((1=1 and 2=2) or 3=3) and 5=6 then 1 else 0 end as result from dual; --0
select case when (1=1 and 2=2) or (3=3 and 5=6) then 1 else 0 end as result from dual; --1
As indirect() is volatile and there is no other way than using indirect in my files, I need to create a UDF equivalent/alternative to indirect.
As far as I have been is :
INDIRECTVBA(ref_text As String, Optional active_A1 As Boolean) As String
If active_A1 = False Then
ref_text = "=" & ref_text
ref_text = Application.ConvertFormula(Formula:=ref_text, fromReferenceStyle:=xlR1C1, toReferenceStyle:=xlA1)
INDIRECTVBA = Range(ref_text)
Else
INDIRECTVBA = Range(ref_text)
End If
End Function
At this point, I'm able to manage :
A1 and R1C1 input with A1 format as default,
In the same sheet or not,
With and without the name of sheet.
I have been googleing for hours, to go there ...
My final need is to handle range such as :
A1:B2 as ref_text => INDIRECTVBA("A1:B2") should return a range as A1:B2
R1C1:R2C3 as ref_text
Thanks for time,
I need to count elements that was in result of SQL query:
db._query('FOR v in visitors FILTER v.ip == "127.0.0.1" return COUNT(v.guid) ')
This request is return my a length of every GUID, but I need to get total number of GUIDs for example: 2.
You need to use the result of the query as input for the COUNT function, and then RETURN this result.
You can replace the RETURN value of the actual query by 1 for performance reasons:
RETURN COUNT(FOR v IN visitors FILTER v.ip == "127.0.0.1" RETURN 1)
Version from 2022!
FOR m IN messages
FILTER DATE_HOUR(m.date) == 3
COLLECT WITH COUNT INTO length
RETURN length
i am working on rdlc report , i have a column in rdlc report , and i want if there is true value , return me "YES"
and if there is false return "NO"
i have tried the following code but it not working
=iif(Field!Application.value)="True","Yes","No"))
thanks in advance.
I thought it was like this
=IIf(Field!Application.Value = true,"yes","no")
1) 'V' is supposed to be capital
2) parenthesis should be at the end.
You can use the IIf command:
=IIf(<Expression as Boolean>, <TruePart as Object>, <FalsePart as Object>) as Object
Like this:
=IIf(Fields!Application.Value = true, "Yes", "No")
This works to me, bye!