How to calculate Field Using Conditional Logic in oracle form
like if i select one item then formula one calculate value else formula2
Sounds like an ordinary IF:
if :block.item = 'A' then
:block.calculated_field := 100 * :block.item_B / 3.14;
elsif :block.item = 'B' then
:block.calculated_field := 200 * :block.item_c * 1.66;
end if;
If that's not it, could you explain it somewhat better? Perhaps even attach screenshot which shows what you need?
use case when like :
case when :block.item = 'A' then
:block.calculated_field := 100 * :block.item_B / 3.14;
when :block.item = 'B' then
:block.calculated_field := 200 * :block.item_c * 1.66;
end
Related
Since this is on of the most common questions in https://t.me/tarantool and https://t.me/tarantoolru, I post the answer here.
space:pairs(from, 'GE'):
take_while(function(x) return x.field <= to end)
-- :totable() or use the result in the for-loop
For multipart keys see https://stackoverflow.com/a/57766656/1135874
You can do it using Lua as well as SQL.
1) Use a stored procedure in Lua, like this one:
function select_between(space_name, index_name, field_name, from, to)
local obj = index_name == nil and box.space[space_name] or box.space[space_name].index[index_name]
local result = {}
for _, tuple in obj:pairs(from, {iterator = 'GE'}) do
if (tuple[field_name] <= to) then
table.insert(result, tuple)
else
break
end
end
return result
end
select_between('test', nil, 'id', 1, 3)
2) Starting with Tarantool 2.0, you can use SQL (provided that you have space format):
box.execute('select * from "test" where "id" between 1 and 3;')
Disclaimer: This is Glua (Lua used by Garry's Mod)
I just need to compare tables between them and return the difference, like if I was substrating them.
TableOne = {thing = "bob", 89 = 1, 654654 = {"hi"}} --Around 3k items like that
TableTwo = {thing = "bob", 654654 = "hi"} --Same, around 3k
function table.GetDifference(t1, t2)
local diff = {}
for k, dat in pairs(t1) do --Loop through the biggest table
if(!table.HasValue(t2, t1[k])) then --Checking if t2 hasn't the value
table.insert(diff, t1[k]) --Insert the value in the difference table
print(t1[k])
end
end
return diff
end
if table.Count(t1) != table.Count(t2) then --Check if amount is equal, in my use I don't need to check if they are exact.
PrintTable(table.GetDifference(t1, t2)) --Print the difference.
end
My problem being that with only one of difference between the two tables, this returns me more than 200 items. The only item I added was a String. I tried many other functions like this one but they usually cause a stack overflow error because of the table's length.
Your problem is with this line
if(!table.HasValue(t2, t1[k])) then --Checking if t2 hasn't the value
Change it to this:
if(!table.HasValue(t2, k) or t1[k] != t2[k]) then --Checking if t2[k] matches
Right now what is happening is that you're looking at an entry like thing = "bob" and then you're looking to see whether t2 has "bob" as a key. And it doesn't. But neither did t1 so that shouldn't be regarded as a difference.
I want to do an event study and need some descriptives around the events I am testing with different window sizes.
Let's assume I have a data set with 10000 observations (stocks, dates, measures) and merge them with an announcement data set. Now, I want to get a dummy variable that is always 0 except for parameters given by me:
if date = announcement_date then;
window_dummy at t-60 to t-11 = 1
or
window_dummy at t-5 to t+5 = 1
I hope I described it appropriately and there is a way because there is no lead function or similar.
Best
M
From what I gather from this, you wish to have additional variable, which creates window (or binning) variable reaching x days to past and future;
First we generate some test data. SAS dates are just numbers so:
data begin;
do i = 21040 to 21080;
my_date= i;
output;
end;
drop i;
run;
Next we calculate the window:
%let act_date= 21060;
%let min_date= %eval(&act_date - 5); /*5 days to past*/
%let max_date= %eval(&act_date + 3); /*3 days to future*/
Then it's left to generate the dummy variable:
data refined;
set begin;
if &min_date <= my_date and
my_date <= &max_date then
dummy = 1;
else dummy = 0;
run;
Now, one can calculate this all in single datastep, but maybe this is more informative way.
Edit: you can specify windows as you please. In your case you could have:
min_date1= %eval(&act_date - 60);
max_date2= %eval(&act_date - 11);
....
Then just add them to the if clause with or operator.
I have DQL query that throws this exception:
[Doctrine\ORM\Query\QueryException] Error: Expected end of string, got '*'
Here is the query:
UPDATE Bundle:Table t SET t.column = :variable * 100
I don't understand the problem with this query, and those two are working:
UPDATE Bundle:Table t SET t.column = 100 * :variable
UPDATE Bundle:Table t SET t.column = 1 * :variable * 100
Any idea?
Is :variable definitely a number (int/float)? If it's a string then it may be that it can't produce a query that's syntactically correct:
UPDATE some table t SET t.column = '1' * 100;
Whereas maybe the versions with a number first "100 * :variable" and "1 * :variable * 100" can cast it correctly because there is an integer first.
Maybe you can post your setParameter() and check if you can call getSQL() to see what the constructed SQL query looks like.
The issue is related to https://github.com/doctrine/orm/issues/8011 and not fixed until today.
Most likely
UPDATE Bundle:Table t SET t.column = ((:variable * 100))
will do the trick and have the parser handle the expression correctly. This has been described in https://github.com/doctrine/orm/issues/8011#issuecomment-758492375.
Does anyone have any tips for calculating percentages in Linq to Entities?
I'm guessing that there must be a more efficient way than returning 2 results and calculating in memory. Perhaps an inventive use of let or into?
EDIT
Thanks Mark for your comment, here is a code snippet, but I think this will result in 2 database hits:
int passed = (from lpt in this.PushedLearnings.Select(pl => pl.LearningPlanTask)
where lpt.OnlineCourseScores.Any(score => score.ActualScore >= ((lpt.LearningResource.PassMarkPercentage != (decimal?)null) ?lpt.LearningResource.PassMarkPercentage : 80))
select lpt).Count();
int total = (from lpt in this.PushedLearnings.Select(pl => pl.LearningPlanTask)
select lpt).Count();
double percentage = passed * 100 / total;
If you use LINQ to Entities and write something along the lines of select x * 100.0 / y in your query then this expression will be converted to SQL and run in the database. It will be efficient.