where-clause

Scala equivalent to Haskell's where-clauses?

空扰寡人 提交于 2019-12-09 08:05:51
问题 Is it possible to use something similar to where-clauses in Scala? Maybe there is some trick I didn't think of? Edit: Thanks for all your answers, they are very much appreciated. To sum up: Local vars, vals and defs can be used to achieve almost the same thing. For lazy evaluation, one can use lazy val (with implicit caching) or function definitions. Ensuring functional purity is left to the programmer. Now just one question remains: Is there a way of putting the value or function definitions

where does the `where` clause come in handy in Haskell

允我心安 提交于 2019-12-08 20:38:41
问题 I find I quite seldom come across situations where I need to use the where clause. However, I do find that I have used it very occasionally in the past. When is the where clause used (i.e. what situations is it used in)? Under what circumstances should I use it? 回答1: There are two excellent answers to this question available on the Haskell Wiki as well: http://haskell.org/haskellwiki/Declaration_vs._expression_style http://haskell.org/haskellwiki/Let_vs._Where Both are used to create local

Why do you have 'where' when there is 'having' [duplicate]

一世执手 提交于 2019-12-08 17:26:39
问题 This question already has answers here : SQL - having VS where (7 answers) Closed 6 years ago . I know this is much discussed, but none of my research could convince me the difference between ' where ' and ' having ' clauses in MySQL. From what I understand we can achieve everything that can be done with 'where' clause using ' having ' . For eg. select * from users having username='admin' . Then why do you need ' where ' clause? Does using where make any performance differences? 回答1: The

Conditional where clause in JPA criteria query

天涯浪子 提交于 2019-12-08 16:27:24
问题 I am facing an issue for JPA criteria query. How can I add multiple where clause in my Criteria Query with if else... My Requirement is: CriteriaBuilder builder = getEm().getCriteriaBuilder(); CriteriaQuery<Object> query = builder.createQuery(Object.class); // From Root<EntityClass> entity= query.from(EntityClass.class); // Select query.multiselect(entity.get("id").get("col1"),entity.get("id").get("col2")); // Where Predicate p1 = builder.and(builder.equal(entity.get("col3"), value3));

Oracle: How to do multiple counts with different where clauses the best way?

限于喜欢 提交于 2019-12-08 15:45:39
问题 I have requirement to count rows with different where clauses from the same table. The following is the required output from me Bu #A #B #C #D #E #F #G #H #J #K #L #M #N GB01 267 284 84 45 35 32 458 801 111 899 892 56 99 NL01 132 844 65 28 26 12 627 321 56 681 1062 127 128 Each column has its own criteria, so far I have the following SQL but it already looks ugly and doesn't exactly return what I need SELECT * FROM ( SELECT c_unit_code, COUNT(*) AS ADVICE_EXPORT, 0 AS CONFIRMATION_EXPORT, 0

Filter based on an aliased column name

梦想与她 提交于 2019-12-08 15:09:24
问题 I'm using SqlServer 2005 and I have a column that I named. The query is something like: SELECT id, CASE WHEN <snip extensive column definition> END AS myAlias FROM myTable WHERE myAlias IS NOT NULL However, this gives me the error: "Invalid column name 'myAlias'." Is there a way to get around this? In the past I've included the column definition in either the WHERE or the HAVING section, but those were mostly simple, IE COUNT(*) or whatever. I can include the whole column definition in this

How to conditionally filter on a column in a WHERE clause?

末鹿安然 提交于 2019-12-08 15:00:50
问题 OK, the umpteenth conditional column question: I'm writing a stored proc that takes an input parameter that's mapped to one of several flag columns. What's the best way to filter on the requested column? I'm currently on SQL2000, but about to move to SQL2008, so I'll take a contemporary solution if one's available. The table queried in the sproc looks like ID ... fooFlag barFlag bazFlag quuxFlag -- ------- ------- ------- -------- 01 1 0 0 1 02 0 1 0 0 03 0 0 1 1 04 1 0 0 0 and I want to do

In Haskell, what is the scope of a where clause when dealing with guards?

二次信任 提交于 2019-12-08 14:43:23
问题 I know they do not hold across pattern matches (i.e. you need to rewrite the 'where' clause for each pattern), but how does the scoping work for guards? e.g. Does this work? myFunction x1 x2 | x1 > x2 = addOne x1 | x1 < x2 = addOne x2 | otherwise = x1 where addOne = (1+) Or should it be this? myFunction x1 x2 | x1 > x2 = addOne x1 where addOne = (1+) | x1 < x2 = addOne x2 where addOne = (1+) | otherwise = x1 回答1: The first one is the correct one. I would suggest you to have a look at the let

How to add to Where clause depending on parameter value

≡放荡痞女 提交于 2019-12-08 14:02:14
问题 I have an sql query that I am wanting to run and want to add something to the where clause if I mark a parameter as true. I didn't think I would need to have the same sql statement twice, but can't find a way to do this. This is what I want. DECLARE @getShipped VARCHAR = 'false'; SELECT DISTINCT Serial_No INTO #Serials FROM Part_v_Container_Change2 AS CC WHERE Change_Date <= @dateEnding *** AND IF @getShipped = 'true' THEN CC.Container_Status = 'Shipped' *** Have tried if statements and case

How to select Unknown Number of Columns in mysql?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 11:48:48
问题 Given the table and names of some columns, I have the following Information schema select query. SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = 'm_college' AND `TABLE_NAME` = 'm_fee' AND COLUMN_NAME NOT IN ('id', 'classid', 'semid') But this select does not give me the rows value for each unknown column I select. All I got is names of the unknown columns. Is it possible to select the values of the rows so that I can have column as key and rows as value pair in