where

Rails 3 sort after .where condition using NOT NULL

丶灬走出姿态 提交于 2019-12-21 20:53:34
问题 I have a ranking which shows the fastest User: @users = User.find.sort { |a, b| b.finished_at <=> a.created_at } Now I hat to add some code to prevent getting an error because of finished_at beeing nil until the user finished. @users = User.find(:all, :conditions => "finished_at IS NOT NULL").sort { |a, b| b.finished_at <=> a.created_at } But sort doesn't work. Is this way of chaining methods flawed? And is find(:all, :conditions => "finished_at IS NOT NULL") the rails 3 way or outdated?

oracle where in limitation to 1000 / hibernate

∥☆過路亽.° 提交于 2019-12-21 12:17:31
问题 Oracle knows the limitation to 1000 elements in the where a in (..) clause. Does this limitation also exist when using Hibernate in conjuction with Oracle? 回答1: This database limitation still exists with hibernate. If you really need to have more than 1000 items in your in clause you will have to split the list yourself in the code and run the query for each block of 1000 keys, then append the result sets together. Note this hack breaks down if your query needs to sort or otherwise aggregate

Create fully dynamic where clause with expression tree and execute on IQueryable

做~自己de王妃 提交于 2019-12-21 12:10:59
问题 At point (3) in my code I have defined a query called query1 in which I defined a .Where lambda expression. This query is in some way dynamic but still contains static elements, it always refers to the Type Employee and its (int) property ClientID. Now I very much like to make the refering to the type and its property dynamic, based on the method parameters which by example are shown below point (1). What I tried to so far is making the static part of the query defined under point (3) fully

Concatenate (glue) where conditions by OR or AND (Arel, Rails3)

 ̄綄美尐妖づ 提交于 2019-12-21 04:57:24
问题 I have several complex queries (using subqueries, etc...) and want to glue them together with OR or AND statement. For example: where1=table.where(...) where2=table.where(...) I would like something like where3=where1.or where2 Next example doesn't work for me: users.where(users[:name].eq('bob').or(users[:age].lt(25))) because of I have several where(..) queries and I want to concatenate them . In other words I have 3 methods: first return first where, second-second, third - OR concatenation.

Laravel 4 - How to use where conditions for relation's column

泪湿孤枕 提交于 2019-12-21 01:42:18
问题 This is what I want, I have two tables. one is 'Restaurants' and other is 'Facilities'. The tables are simple.. and One-To-One relations. like there is a restaurant table with id , name , slug , etc and another table called facilities with id , restaurant_id , wifi , parking , etc Here are my models: class Restaurant extends Eloquent { protected $table = 'restaurants'; public function facilities() { return $this->hasOne('Facilities'); } } class Facilities extends Eloquent { protected $table =

MySQL query match with alias WHERE not working

折月煮酒 提交于 2019-12-20 05:31:57
问题 why does my sintax is not right? SELECT *, MATCH(tags,title,description) AGAINST ('asd jhbdckdsb' IN BOOLEAN MODE) AS score FROM blogs WHERE score > 0 ORDER BY score DESC, insert_datetime DESC, id DESC ; the problem seems to be on WHERE condition :/ 回答1: invisible columns and column alias are not allowed in WHERE so use HAVING HAVING score > 0 instead of WHERE 回答2: You cannot use a column alias in the WHERE clause. You must repeat the MATCH a second time. 来源: https://stackoverflow.com

CASE in WHERE CLAUSE in MYSQL

点点圈 提交于 2019-12-20 03:32:50
问题 The question is as simple as the title says,But here is one logic. Here is my code CREATE TABLE `inf_brand_images` ( `id` bigint(99) NOT NULL AUTO_INCREMENT, `brand` varchar(255) NOT NULL, `thumb` text NOT NULL, `is_active` int(2) NOT NULL DEFAULT '1', `cmp_brand` varchar(1024) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=6458 DEFAULT CHARSET=latin1 Here is data in this table ID | brand | thumb |is_active| cmp_brand 1 | NIKE | a.png | 1 | 2 | DUNHILL| b.png | 1 | 3 | NIKE | c

MS Access Insert where not exists

不问归期 提交于 2019-12-20 03:17:02
问题 I have the following table: +-----------+--------+ | FirstName | Active | +-----------+--------+ | Rob | TRUE | | Jason | TRUE | | Mike | FALSE | +-----------+--------+ I would like to insert 'John' (with Active=True) only if an entry for John doesn't exist already where Active=True. I try the following: insert into testTable (FirstName, Active) values ('John',True) where not exists (select 1 from testTable where FirstName='John' and Active=True) but i get 'Query input must contain at least

mysql WHERE MATCH AGAINST

微笑、不失礼 提交于 2019-12-20 02:59:06
问题 I am having a problem with a mysql and MATCH AGANIST. I got this row in my database : 1:{Czy jesteśmy tutaj sami};2:{Margit Sanoemo} I want to find this by following query : SELECT * FROM data WHERE MATCH (params) AGAINST('*argi*' IN BOOLEAN MODE) but I got an empty row. However with this query : SELECT * FROM dataWHERE MATCH (params) AGAINST('margi*' IN BOOLEAN MODE) I get want I want. Can you help me with double ** in params ? AGAINST('*argi*' IN BOOLEAN MODE) 回答1: + A leading plus sign

Conditional in MYSQL where clause

人盡茶涼 提交于 2019-12-19 07:51:22
问题 I have a query that if a flag called OrderBy is 1 then it is a calendar event and I need to check for a range between two date time fields. Whereas all other types we just check for the day you are viewing. I research if statements and saw many posts where it was suggested a case be used so I tried to implement it into my query. My query needs the condition in the where. I know I have syntax issues and that is why I am here in the hopes that someone could point out the correct way to do this.