where-clause

Will Postgres push down a WHERE clause into a VIEW with a Window Function (Aggregate)?

*爱你&永不变心* 提交于 2019-12-06 20:04:10
问题 The docs for Pg's Window function say: The rows considered by a window function are those of the "virtual table" produced by the query's FROM clause as filtered by its WHERE, GROUP BY, and HAVING clauses if any. For example, a row removed because it does not meet the WHERE condition is not seen by any window function. A query can contain multiple window functions that slice up the data in different ways by means of different OVER clauses, but they all act on the same collection of rows

LINQ WHERE with OR

末鹿安然 提交于 2019-12-06 19:31:45
问题 I use LINQ to create my where clause like so: var query = from x in context.Xs select x; if (y == ...) { query = query.Where(x => x.Y == 1); } I have bunch of these "if .... where" statements. The issue I have is that all of those wheres join where clauses using AND but I need all my where clauses to use OR. Is there an easy way to port this code into where OR code? Or even what is the easiest way to do this with OR? Thanks. 回答1: PredicateBuilder is the perfect solution for your problem. It

PHP PDO: Array in Update SQL WHERE IN () clause

青春壹個敷衍的年華 提交于 2019-12-06 15:42:50
I'm trying to take an array of ID numbers and update every row with that ID number. PHP PDO code follows: private function markAsDelivered($ids) { $update = $this->dbh->prepare(" UPDATE notifications SET notified = 1 WHERE notification_id IN ( :ids ) "); $ids = join(',', $ids); Logger::log("Marking the following as delivered: " . $ids, $this->dbh); $update->bindParam(":ids", $ids, PDO::PARAM_STR); $update->execute(); } However, when this is run, only the first item in the list is getting updated, although multiple ID numbers are being logged. How do I modify this to update more than one row? A

SELECT WHERE IN (subquery) slow

房东的猫 提交于 2019-12-06 15:38:17
问题 I've tried the solution here, but it doesn't work. My table is like this: `Index` uid dept ........................... 1 001 dept1 2 001 dept2 3 001 dept3 4 002 dept2 5 002 dept3 6 002 dept4 7 003 dept1 8 003 dept5 9 004 dept1 10 004 dept6 I want to retrieve all the rows with a particular dept . That is, If I want to retrieve dept1 , I want to retrieve all rows except uid=002, since there's no dept1 for uid=002. The query string is slow even when using index: SELECT id FROM table WHERE uid IN

Laravel multiple where clauses in query from given array

℡╲_俬逩灬. 提交于 2019-12-06 14:10:25
I hope the title describes my problem good as enough. I tried to make a geosearch-function in laravel. The queries as its own are correct. Now I try to get all articles from my table, whose match with the gotten zipcode of a former query. All functions I use you can found here: Laravel 5 add results from query in a foreach to array ). But now I want to perform one query, within multiple or dynamic where clauses (with or). The print_r($zipcodes) of my former query (get all zipcodes in a range from a zipcode $zipcodes = $this->getZipcodes($zipCoordinateId, $distance); ) outputs: Array ( [0] =>

Oracle sql MERGE INTO with a single where clause

情到浓时终转凉″ 提交于 2019-12-06 14:03:31
I have the following SQL code (this is how much I've got so far): MERGE INTO SCHEMA1.TABLE_1 table1 USING ( SELECT DISTINCT table2.column1, view1.column2 FROM SCHEMA2.TABLE_2 table2 LEFT JOIN SCHEMA2.VIEW_1 view1 ON table2.column2 = view1.column3 ) t2 ON (table1.column3 = t2.column1 ) WHEN MATCHED THEN UPDATE SET table1.column4 = t2.column2; The following is the definition of VIEW_1 : CREATE VIEW SCHEMA_2.VIEW_1 AS (SELECT SCHEMA_2.TABLE_1.COLUMN_1, SCHEMA_2.TABLE_2.COLUMN_1, SCHEMA_2.TABLE_2.COLUMN_2, SCHEMA_2.TABLE_2.COLUMN_3, SCHEMA_2.TABLE_5.COLUMN_1, SCHEMA_2.TABLE_6.COLUMN_1, SCHEMA_2

SQL Server, choosing from two TABLEs using IF statement inside WHERE statement depending on the parameter

南楼画角 提交于 2019-12-06 11:05:55
问题 How can I do the following in SQL Server DECLARE @Local nvarchar(20) SET @Local = 'True' SELECT * FROM My_Table WHERE my_ID IN (IF @Local = 'True' SELECT AllIDs FROM ATable ELSE SELECT TeamIDs FROM TeamTable ) 回答1: Go for a union :- SELECT * FROM My_Table WHERE my_id IN ( SELECT AllIDs AS MyIDs FROM ATable WHERE @Local = 'True' UNION SELECT TeamIDs AS MyIDs FROM TeamTable WHERE @Local <> 'True' ) 回答2: SELECT * FROM mytable WHERE my_id IN ( SELECT allids FROM atable WHERE @Local = 'True' )

MySQL exact word existence check in a table Field

那年仲夏 提交于 2019-12-06 08:13:59
问题 I've a Query. Is there any built-in function or any other method associated with MySQL, which will return rows that contains EXACT word in the database table field? I'm aware that with MySQL LIKE operator, You can search for a specified pattern in a column which will match a string value against a pattern string containing wild-card characters. But With MySQL LIKE clause, It'll return substring entries too. Eg. Suppose 3 column values are like below: 1. "Take another shot of courage" 2. "The

Converting conditionally built SQL where-clause into LINQ

℡╲_俬逩灬. 提交于 2019-12-06 07:10:19
So I didn't see a question here that really answers this question. It's kinda a newbie question about linq but I would like to know if it would be possible to convert the following sql query (built using C#) into a linq query: public void DoSomeQuery(bool whereCriteria1, bool whereCriteria2) { string sqlQuery = "SELECT p.*"; string fromClause = " FROM person p"; string whereClause = " WHERE "; if (whereCriteria1) { fromClause += ", address a"; whereClause += " p.addressid = a.addressid and a.state = 'PA' and a.zip = '16127' " } if (whereCriteria2) { fromClause += ", color c"; whereClause += "

Are Linq-To-Sql Dynamic-Where-Clauses Even Possible in Framework 3.5?

别来无恙 提交于 2019-12-06 03:49:15
问题 UPDATE: It Is Now Working I was able to finally get it completed. A working-example is detailed in an answer below (which I will be able to mark-off in 2 days). Everything Below Here Was Part of the Original Question For the last 3 days, I have been trying to build a dynamic-where-clause on a DBML DataContext using code samples from questions posted here and from other sources as well... none have worked ! For the reasons below, I am beginning to wonder if this is even POSSIBLE using under