Can I Add SQL QUERY in EXPRESSION MAPFILE ? like this ..
CLASS
Name '> 0'
EXPRESSION (SELECT * from tb_kelurahan where id_kecamatan='[id_kecamatan]' > 0)
COLOR 20 215 0
OUTLINECOLOR 0 0 0
END # Class
No. But as an alternative you can add the sql as an additional column to the DATA statement and then reference that in the expression.
DATA "the_geom from (select case when id_kecamatan>0 then 1 else 0 end as myexpress, the_geom, ...) as foo ...."
and then use:
EXPRESSION ([myexpress] = 1)
Related
I am trying to use CASE in my query. I have to calculate the difference between required_number and vehicle_quantity. If it is less than or equal to 0 then I need value 0 otherwise the difference value. I am trying following code directly in phpmyadmin. But I am getting error:
Notice in ./libraries/sql-parser/src/Utils/Query.php#427
Undefined property: SqlParser\Components\CaseExpression::$expr
This is the query I have tried so far.
SELECT
required_number,
vehicle_quantity,
CASE
WHEN (
required_number - vehicle_quantity
) <= 0 THEN
'0'
ELSE
(
required_number - vehicle_quantity
)
END AS income_amt
FROM
vehicles
WHERE
id = 22
Can anybody help me what mistake I did in my query. Thank You.
Try this:
SELECT required_number,
vehicle_quantity,
(CASE
WHEN ((required_number - vehicle_quantity) <=0) THEN 0
ELSE (required_number - vehicle_quantity)
END) AS extra
FROM vehicles
WHERE mun_id=22
TRY THIS: you have to use 0 instead of '0' because you are doing integer based calculation so you can't define string instead
SELECT
required_number,
vehicle_quantity,
CASE WHEN (required_number - vehicle_quantity) <= 0 THEN
0
ELSE
(required_number - vehicle_quantity)
END AS income_amt
FROM vehicles
WHERE id = 22
I want to sum all the values of the column, using if condition same as the column expression:-
The Expression of the normal column:-
iif(Fields!mcount.Value <> 0 And Fields!TaxCode.Value = 1 ,Fields!InputAmnt.Value,0)
The Expression to sum, I used 2 codes and the same result "#Error" appeared in both cases
sum(iif(Fields!mcount.Value <> 0 And Fields!TaxCode.Value = 1 ,Fields!InputAmnt.Value,0))
and
iif(Fields!mcount.Value <> 0 And Fields!TaxCode.Value = 1 ,sum(Fields!InputAmnt.Value),0)
any help ?
Try adding VAL from the InputAmnt field. See below expression.
=SUM(iif(Fields!mcount.Value <> 0 And Fields!TaxCode.Value = 1 ,VAL(Fields!InputAmnt.Value),0))
I use case when in MySQL like this:
select name, age, time, countDay, dvt, total, dateLogin,
(total - datediff(NOW(), dateLogin)) as totalVal18,
(total - age) as totalVal22
case dvt
when dvt = 0 then countDay = totalVal18
when dvt = 1 then countDay = totalVal22
Update 1:
Struct table is: dvt, total, countDay is double type.
dateLogin is datetime type.
User input is dateLogin and age.
Output using countDay to check values. Like:
where countDay >= 18.
dvt is tinyint. dvt like your age > 18 or age < 18
Error like:
error like case dvt
when dvt = 0 then at line 2
When using formula it happens error? How to using the formula in case when MySQL?
You have incorrectly combined the 2 versions of the case structure.
Either use
case dvt
when 0 then totalVal18
when 1 then totalVal22
end as countDay
Or
case
when dvt = 0 then totalVal18
when dvt = 1 then totalVal22
end as countDay
forms. See mysql's documentation on case
Update
You cannot use column aliases this way, you need to include the formula in the case statement as well.
Check this Sample Here table refers to your table name
SELECT CASE
WHEN dvt > 18 THEN 1
ELSE 0 END AS
countDay
FROM table
I don't understand how sas calculates the value for PATIENT , I've looked everywhere but there seems to be no documentation for how sas, calculates the formulas in the case parenthesis, I only know that when the value of
PATIENT is even the CASE expression has a Boolean result of 1 , 0 or 2, but I just don't see how to get the value out of the expression, could someone please explain me?
PROC SQL;
CREATE TABLE TESTMED AS
SELECT PATIENT,
CASE ((PATIENT/2 = INT(PATIENT/2)) +
(PATIENT = .))
WHEN 1 THEN 'Med A' WHEN 0 THEN
'Med B' ELSE 'Error' END AS DOSEGRP
LENGTH=5
FROM VITALS
ORDER BY PATIENT;
QUIT;
I can't see any error.
if patient could be . 0 1 2 this will be (first expression + second expression):
0 ---> {0=0}true(1) + {patient=.} false(0) = 1
1 ---> {0.5=0}false(0) + {patient=.} false(0) = 0
2 ---> {1=1}true(1) +{patient=.} false(0) = 1
. ---> {.=.} true(1) + {patient=.} true(1) = 2
If you want to see the result of that boolean expression you can simply use:
PROC SQL;
CREATE TABLE TESTMED AS
SELECT patient,
((PATIENT/2 = INT(PATIENT/2)) + (PATIENT = .)) AS result
LENGTH=5
FROM VITALS
ORDER BY PATIENT;
QUIT;
and you will see that the results are correct.
So your boolean expression could assume only 3 values:
(1=0+1)
(0=0+0)
(2=1+1)
When 0 you assign MEDA;
When 1 you assign MEDB;
When 2 you assign ERROR;
And ERROR is assigned for missing values.
1st expression:
{missing/2=missing} = {int(missing)=missing} [errors are reported as missing]
missing=missing ---> true ---> 1
2nd expression:
missing=missing ---> true ---> 1
result:
1+1=2 ---> ERROR
SAS evaluates boolean expressions to 1 (true) or 0 (false). So your expressions is the sum of two of these. So the possible answers are 0, 1 or 2.
The first expression, (PATIENT/2 = INT(PATIENT/2)), will be true when PATIENT is even or missing. The second expression, (PATIENT = .), will be true when PATIENT is missing. So a result of 2 means that PATIENT is missing a result of 1 means that PATIENT is even and a result of 0 means that patient is odd.
So you could rewrite the case statement as:
CASE WHEN MISSING(PATIENT) then 'Error'
WHEN MOD(PATIENT,2)=1 then 'Med A'
ELSE 'Med B'
END AS DOSEGRP
I'm working on the following simple query. I want to innerjoin squad s and group g tables but with condition (#ZeroOrOne parameter will be 0 or 1)
WHERE
CASE WHEN IsNumeric(#ZeroOrOne) = 0 THEN
s.TeamId=g.Team1Id --if #ZeroOrOne value is 0 then perform this statement
ELSE
s.TeamId=g.Team2Id --if #ZeroOrOne value is 1 then perform this statement
What is the right way; should I change my query or logic?
Try this.
WHERE
s.TeamId = CASE WHEN IsNumeric(#ZeroOrOne) = 0 THEN g.Team1Id
ELSE g.Team2Id END
OR you can also use this in ON clause
JOIN Table s
ON s.TeamId = CASE WHEN IsNumeric(#ZeroOrOne) = 0 THEN g.Team1Id
ELSE g.Team2Id END