where-clause

Why is it so uncommon to use type signatures in where clauses?

被刻印的时光 ゝ 提交于 2019-12-22 01:26:46
问题 Does it help the compiler to optimise, or is it just surplus work to add additional type signatures? For example, one often sees: foo :: a -> b foo x = bar x where bar x = undefined Rather than: foo :: a -> b foo x = bar x where bar :: a -> b bar x = undefined If I omit the top level type signature, GHC gives me a warning, so if I don't get warnings I am quite confident my program is correct. But no warnings are issued if I omit the signature in a where clause. 回答1: Often definitions in where

SQL group by: using where-clause logic to filter results based on aggregate functions

喜夏-厌秋 提交于 2019-12-21 20:17:30
问题 I have a basic group by/avg statement: select url, avg(contentping+tcpping), count(*) from websites ws, ping pi where ws.idwebsite = pi.idwebsite and errortype is null group by url order by avg(contentping+tcpping) asc; What I want to do now is to drop any results which have a higher than average ping of 500. How can I do this...? 回答1: just add a having clause: select url, avg(contentping+tcpping), count(*) from websites ws, ping pi where ws.idwebsite = pi.idwebsite and errortype is null

Delete SQLite Row with where clause with multiple clauses

泄露秘密 提交于 2019-12-21 08:01:24
问题 I've been searching around and not managed to find a solution or working example so here goes. I've set up an SQLite database which has five columns with different fields which effectively builds a list for the user. There will be multiple values in the list that are the same, save for the ROWID which is set to auto increment. Neither the user nor the program will know the ROWID once a value has been entered into the database, so I want for the user to be able to remove one row if it contains

MYSQL use 'LIKE' in 'WHERE' clause to search in subquery

笑着哭i 提交于 2019-12-21 07:24:20
问题 How would you use 'LIKE' to search in a subquery? E.g. i've tried doing this, but doesn't work: SELECT * FROM mytable WHERE name LIKE '% (SELECT name FROM myothertable) %' I have this so far: SELECT * FROM t1 WHERE t1.name IN (SELECT t2.name FROM t2) AND (t1.title IN (SELECT t2.title FROM t2) OR t1.surname IN (SELECT t2.surname FROM t2)) It's working ok as it returns exact matchs, but it doesn't seem to return my other records that are similar, so I would like to also check that: t1.title

Haskell - defining a function with guards inside a 'where'

这一生的挚爱 提交于 2019-12-21 07:08:25
问题 I'm just starting out at teaching myself Haskell. This code is supposed to do prime factorisation: divides :: Integer -> Integer -> Bool divides small big = (big `mod` small == 0) lowestDivisor :: Integer -> Integer lowestDivisor n = lowestDivisorHelper 2 n where lowestDivisorHelper m n | (m `divides` n) = m -- these should belong to lowestDivisorHelper | otherwise = lowestDivisorHelper (m+1) n primeFactors :: Integer -> [Integer] primeFactors 1 = [] primeFactors n | n < 1 = error "Must be

LINQ Where with AND OR condition

半腔热情 提交于 2019-12-21 03:13:13
问题 So I have managed to get this query working List<string> listStatus = new List<string>() ; listStatus.add("Text1"); List<string> listMerchants = new List<string>() ; listMerchants.add("Text2"); from item in db.vw_Dropship_OrderItems where listStatus.Contains(item.StatusCode) && listMerchants.Contains(item.MerchantId) select item; Here I would like to check if listStatus and listMerchants are not null only then put them inside WHERE clause. Like if listMerchants is null then query will be like

LINQ Join Where Clause

[亡魂溺海] 提交于 2019-12-20 10:25:36
问题 I'm struggling with a join/where clause with what is a rather simple sql select statement. I am trying to retrieve a list of product information from tb1 with the where condition behind situated in tbl2 but this must be joined by three different columns. so the SQL would look something along the lines of: SELECT tb1.* FROM tb2 INNER JOIN tb1 ON tb2.Col1 = tb1. Col1 AND tb2.Col2 = tb1. Col2 AND tb2.Col3 = tb1.Col3 WHERE (tb2.Col1 = col1) AND (tb2.Col2 = col2) AND (tb2.Col4 = string) ColX is

Using insertWithOnConflict for update or insert

我是研究僧i 提交于 2019-12-19 16:54:45
问题 I need to insert or update and I found the method insertWithOnConflict of the SQLiteDatabase, but I do not know how it checks if the entry already exists. Theoretically I need a "Where" argument to check if a certain ID exists, and if so, it should replace all other columns. This is what I have now, but I don´t think that the second argument is the unique id ContentValues args = new ContentValues(); args.put(AppDatabase.COLUMN_ID, entry.getId()); args.put(AppDatabase.COLUMN_NAME, entry

Cassandra: Query with where clause containing greather- or lesser-than (< and >)

流过昼夜 提交于 2019-12-19 06:25:21
问题 I'm using Cassandra 1.1.2 I'm trying to convert a RDBMS application to Cassandra. In my RDBMS application I have following table called table1: | Col1 | Col2 | Col3 | Col4 | Col1: String (primary key) Col2: String (primary key) Col3: Bigint (index) Col4: Bigint This table counts over 200 million records. Mostly used query is something like: Select * from table where col3 < 100 and col3 > 50; In Cassandra I used following statement to create the table: create table table1 (primary_key varchar,

MYSQL Select rows where date is older than datetime

[亡魂溺海] 提交于 2019-12-18 19:07:03
问题 I am coding a status item for a website and need to load statuses older than a variable that contains a datetime. So the database has a field called added date which is a datetime field and I have a string in datetime format and i want to select all rows older than my datetime format string. How would this be structured in MYSQL? Thanks in advance. 回答1: select status_column from your_table where added_date < '2012-05-12' 回答2: mysql DATETIME type is used for values that contain both date and