clause

Using variable in a LIMIT clause in MySQL

夙愿已清 提交于 2019-12-16 22:46:13
问题 I am writing a stored procedure where I have an input parameter called my_size that is an INTEGER . I want to be able to use it in a LIMIT clause in a SELECT statement. Apparently this is not supported, is there a way to work around this? # I want something like: SELECT * FROM some_table LIMIT my_size; # Instead of hardcoding a permanent limit: SELECT * FROM some_table LIMIT 100; 回答1: A search turned up this article. I've pasted the relevant text below. Here's a forum post showing an example

MySQL where clause and ordering by avg() as a sub query

Deadly 提交于 2019-12-14 02:18:47
问题 Although I can group and order by on an aliased sub query, I can't use the alias in a where clause. Do I need to use a join instead? Works: SELECT entries.*, (SELECT avg(value) FROM `ratings` WHERE ratings.entry_id = entries.id) as avg_rating FROM `entries` ORDER BY avg_rating DESC Fails ("unknown column 'avg_rating' in where clause"): SELECT entries.*, (SELECT avg(value) FROM `ratings` WHERE ratings.entry_id = entries.id) as avg_rating FROM `entries` WHERE avg_rating < '4.5000' ORDER BY avg

How to use like clause query in rails?

旧街凉风 提交于 2019-12-12 10:07:58
问题 I wanted to get a json format of the data when searching for the keyword so I use LIKE clause and query like this "select * from employees where fname like ? or mname like ? or lname like ? or username like ? or id like ?", str, str, str, str, str but I want to code it using rails. I have this code in my controller def showemployees str = params[:str] render json: @employee = Employee.where(Employee.employees[:fname].matches("%#{str}%")) or (Employee.employees[:mname].matches("%#{str}%")) or

WHERE IN clause in Android sqlite?

二次信任 提交于 2019-12-12 07:13:41
问题 I can't get WHERE IN clause to work on android SQLite database. Is there any way to execute a statement like this in android? : SELECT body FROM table1 WHERE title IN ('title1', 'title2', 'title3') 回答1: You can use TextUtils.join(",", parameters) to take advantage of sqlite binding parameters, where parameters is a list with "?" placeholders and the result string is something like "?,?,..,?" . Here is a little example: Set<Integer> positionsSet = membersListCursorAdapter

Cake PHP 3 needs limit option for find all method

拟墨画扇 提交于 2019-12-11 10:16:26
问题 Inside a cell I need to access the TreeOptions model. So I've wrote this : $this->loadModel( 'TreeOptions' ); $i = $this->TreeOptions->find( 'all' ); But when I do the foreach like this : foreach( $i as $row ) debug( $row->description ); It only returns the last record of the result. The only way I've found to make it work as desired is adding the limit clause : $i = $this->TreeOptions->find( 'all', [ 'limit' => 200 ] ); And then, I can get the whole set of records. What am I missing ? Thanks

Elixir: function overloading with different arity

為{幸葍}努か 提交于 2019-12-10 13:08:45
问题 is there any way to define overload functions with different arity, e.g in C# I can just do: foo(bar) or foo(bar, baz) In Elixir, the only way to do that would be to put them in separate modules, which will get messy pretty quickly. Is there any way around it? Edit: I had made a wrong assumption. The examples of overloaded functions I saw happened to have the same arity, so I (wrongly) assumed that this was a requirement. Functions are uniquely identified by their name and arity, so you can

How to do a WHERE…IN… clause in LinqToSql?

吃可爱长大的小学妹 提交于 2019-12-10 10:47:13
问题 Bear with me, I'm beginning: How can I select multiple elements using a WHERE...IN... type of clause as in select * from orders where orderid in (1, 4, 5) in LinqToSql? I'd prefer not to have a lambda expression since they scare me. Thanks in advance! 回答1: LINQ has "Contains" which is like "IN" but expressed the other way round - an element isn't "in" a set, a set "contains" an element. int[] validIds = { 1, 4, 5 }; var query = from order in db.Orders where validIds.Contains(order.Id) select

Oracle SQL Constraint where clause

情到浓时终转凉″ 提交于 2019-12-10 09:42:11
问题 I have the table Tester on oracle with the following columns: TesterID TesterName IsDefault Application_ID TesterID is the primary key. Now I want that there can only be one Default Tester, which means only one Tester can have the calues IsDefault =Y at an ApplicationID. I tried it with a constraint: alter table Tester add constraint Tester_ISDEFAULT UNIQUE(IsDefault,Application_ID); Is it possible to make the unique key on where isdefault= Y? Thanks for help! 回答1: Not with a UNIQUE

AndoridSQLite数据库开发基础教程(9)

萝らか妹 提交于 2019-12-09 16:00:02
AndoridSQLite数据库开发基础教程(9) 添加视图 视图是从一个或几个基本表(或视图)中导出的虚拟的表。通过视图可以看到表的内容。下面为数据库添加视图,操作步骤如下: (1)打开的数据库,单击左下角的齿轮按钮,选择其中的Create View选项,弹出View Creator对话框,如图1.20所示。 图1.20 View Creator对话框 (2)在View name文本框中输入视图的名称,如Student。在As clause文本域中输入相应的SQL语句,如图1.21所示。 图1.21 View Creator对话框 (3)单击Save按钮后,退出View Creator对话框。此时,一个名为Student的视图就添加到了数据库中,如图1.22所示。 图1.22 Student视图 来源: oschina 链接: https://my.oschina.net/u/1585857/blog/3124635

“Not equal” sign in Visual Prolog?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 07:43:25
问题 I can't find any documentation on "not equal" sign in Visual Prolog. Please provide the right solution of this problem: class predicates sister : (string Person, string Sister) nondeterm(o,o). clauses sister(Person, Sister) :- Person [not-equal-sign] Sister, parent(Person, Parent), parent(Sister, Parent), woman(Sister). 回答1: I don't know what do you mean by "not equal" (does not unify?), but you could try these: X \= Y not(X = Y) \+ (X = Y) 回答2: Documentation for the second variant pointed