Hi im trying to do an event alarms system that It is thought to depend on a list of undeterminated concatened conditional rules. Here comes my logical problem, when im trying to structure the database to save this conditional rules in a table, i cant figure out how exactly trace the hierarchy of the expressions, for example if i wanna save the conditión
[(1 =< 2 && 2 == 2) || (0 == 0 || 1 == 1)] && (1 == 1) or any undeterminated number of concatened conditional rules. Can anybody help o almost understand me ?
P.D: Sorry my bad english (:
Related
I am building a sports web app. I want a query that takes a list of players, and checks whether their game for that week has started yet.
The following query works for me, but I need to explicitly type out each player in the list. If I want my list to be dynamically sized, this will not work. Is there anything I can construct this query in a smarter way?
SQL Alchemy query:
db.session.query(Game.start).filter(Game.week_id == self.week_id).filter(or_(Game.home_team == self.players[1].team, Game.away_team == self.players[1].team, Game.home_team == self.players[0].team, Game.away_team == self.players[0].team)).all()
The query then looks like this:
SELECT game.start AS game_start
FROM game
WHERE game.week_id = %(week_id_1)s
AND (%(param_1)s = game.home_team_name OR
%(param_2)s = game.away_team_name OR
%(param_3)s = game.home_team_name OR
%(param_4)s = game.away_team_name)
Got it using in_
db.session.query(Game).filter(Game.week_id == self.week_id, Game.start==True).filter(or_(Game.home_team_name.in_([p.team_name for p in self.players]), Game.away_team_name.in_([p.team_name for p in self.players]))).all()
I have a DQL query object which we've implemented (copying a legacy application). The output has to match the legacy verbatim.
The static fields worked like a charm - but now we've encountered more complex computed fields, such as:
IF(
wo.date_approved = 0,
0,
IF(
ship.date_shipped > wo.date_approved,
ROUND(
IF(
(ship.date_shipped - wo.date_approved) > wo.time_inactive,
(ship.date_shipped - wo.date_approved) - wo.time_inactive,
ship.date_shipped - wo.date_approved
) / 86400, 2),
0
)
) AS TAT,
This is not possible to express using the query builder/DQL. I had hoped to possibly adjust the query right before execution (after parameters have been bound but before execution).
Using a placeholder or similar I would search and replace that with the series of computed fields...
I can't figure out a way to make this happen?!?! :o
Alex
Apologies for posting a new question but I just can't think how to search for this question.
I'm creating a Crystal Report with multiple parameters and at the moment each one is connected by an ‘AND’ in the Report > Selection Formulas part of the report (not the SQL command part).
I haven’t fully authored the report and it contains lots of arrays to deal with multiple text values and wildcard searches but I think my question should be more around logic than the technical functions.
So…
Parameters are for things like product code, date range, country, batch number etc.
Currently the parameters I’m concerned with are Faults and keyword searches for complaints against products.
(Query 1) If all other parameters are set to default I can enter Fault Combination = ‘Assembly – Code’ and that gives me 17 records.
(Query 2) Entering keyword = ‘%unit%’ gives me 55 records.
The 2 parameters are connected by an AND so if I use Fault Combination = ‘Assembly – Code’ and Keyword = ‘%unit%’ then I get 12 records. If the connect the 2 queries with OR then I get 12 records.
If I compare the unique records, in excel, between query 1 & 2 then there are 60 records with Fault Combination = ‘Assembly – Code’ OR keyword = ‘%unit%.
How can write the parameter formula to get the 60 unique records with one query?
Many thanks!
Gareth
Edit - Code Added
This is the segment i'm concerned with. The arrays are defined earlier in the statement and the '*' & '%' parts of the query below are just to deal with the different wildcard operators between SQL and Crystal. There are a lot of other parameters but these 3 are the only ones that need the OR kind or connection.
Hope that helps!
(IF "%" LIKE array_fn2
THEN ((ISNULL({Command.FaultNoun})=TRUE) OR ({Command.FaultNoun} LIKE '*'))
ELSE IF {Command.RecordType} = 'Complaint'
THEN ({Command.FaultNoun} like array_fn2)
ELSE ((ISNULL({Command.FaultNoun})=TRUE) OR ({Command.FaultNoun} LIKE '*'))) AND
(IF "%" LIKE array_fa2
THEN ((ISNULL({Command.FaultAdjective})=TRUE) OR ({Command.FaultAdjective} LIKE '*'))
ELSE IF {Command.RecordType} = 'Complaint'
THEN ({Command.FaultAdjective} like array_fa2)
ELSE ((ISNULL({Command.FaultAdjective})=TRUE) OR ({Command.FaultAdjective} LIKE '*'))) AND
(IF ("%" LIKE array_k2) OR ({Command.RecordType} = 'Sale')
THEN ((ISNULL({Command.ActualStatements})=TRUE) OR ({Command.ActualStatements} LIKE '*')
OR (ISNULL({Command.ResultsAnalysis})=TRUE) OR ({Command.ResultsAnalysis} LIKE '*')
OR (ISNULL({Command.Observation})= TRUE) OR ({Command.Observation} LIKE '*'))
ELSE
({Command.ActualStatements} like array_k2) OR
({Command.ResultsAnalysis} like array_k2) OR
({Command.Observation} like array_k2))
I need to implement SCD Type 2
this is my condition in my split condition before updating my RecordEndDate and eventually adding it in the database. But even though it does not satisfy the condition it still keeps on adding it in the database
((PlateNo == Stage_PlateNo)) && (([Car Name] != [Stage_Model]) ||
([Manufacturer] != [Stage_Manufacturer]) ||
[Year Model] != Stage_Year ||
[Car Body Type] != Stage_BodyType ||
Transmission != Stage_Transmission ||
[Daily Rate (in Peso)] != Stage_DailyRate
)
IMO your requirements are far too complex to attempt in an SSIS Expression. I recommend you recode this logic in a Script transformation. I would pre-create a new Column e.g. Include_Row and in the Script set it's value to yes or no.
This approach will give you much more code flexibility and better debugging possibilities.
How can it implement this in pymongo?
number == 100 or (number >=10000 and number < 10100)?
currently, I am doing it with
*condition['number'] = {'$gte':input_number * 100, '$lt':(input_number + 1) * 100}*
and then query with the condition.
But I don't know how to add "number == 100". Thanks!
The answer is:
condition['$where'] = '(this.number + "").substr(0, 3) == "%d"' % input_number
All I learnt from this is, you can do the query with where and the content for where is a javascript function or something.
But please note that this stupid method is quite slow.