where

Getting count by drilling down through relations

五迷三道 提交于 2019-12-23 01:37:10
问题 I'm using Rails 4 and I want to get a count of votes for each individual post review for a given post. Schema: Post PostReview PostReviewVote id post_id post_review_id user_id user_id voted_on_date I have something like: table.table.table-striped.table-hover thead tr th Post Name th Reviews Created For Post th Total Votes in All Reviews For Post tbody - for post in @posts tr td= post.name td= PostReview.where(post_id: post.id).size td= PostReview.where(post_id: post.id).PostReviewVotes.size

Oracle Conditional where clause

↘锁芯ラ 提交于 2019-12-22 11:23:00
问题 is there any way to write query with following functionality, add where clause as a conditional way, select e.emp_id, emp.admin_user from employees e if emp.admin != 'Y' then query run with where clause else query run without where clause ? 回答1: Using a CASE expression in the WHERE clause should do the trick. When you say you don't need the where clause if condition is not met, then all you want is a condition like WHERE 1 = 1 , i.e. when condition is not met then return all rows. So, you

SQL WHERE depending on day of week

荒凉一梦 提交于 2019-12-22 11:21:29
问题 I have a requirement to check records up to differing dates, depending on which day of the week it is currently. On a Friday I need for it to look at the entire next week, until Sunday after next. On any other day it should check the current week, up until the coming Sunday. I have the below currently but it's not working due to syntax error. Is it possible to do a CASE WHEN inside a WHERE clause? WHERE T0.[Status] IN ('R','P') AND CASE WHEN DATEPART(weekday,GETDATE()) = '5' THEN T0.[DueDate]

Hibernate - class level @Where annotation is not enforced on collections of that class?

雨燕双飞 提交于 2019-12-22 10:52:12
问题 I have annotated a Hibernate entity with a @Where attribute at the class level. This restricts which entities are loaded when I query it directly, but it does not seem to be applied to collections of that class. Is that to be expected? The docs are not clear on this: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-class where (optional): specifies an arbitrary SQL WHERE condition to be used when retrieving objects of this class. That sounds to me

Laravel Eloquent ORM - Complex where queries

谁说胖子不能爱 提交于 2019-12-22 09:25:44
问题 I have the following query: DB::select("SELECT * FROM mod_dns_records WHERE (scheduled = 'N' AND scheduleTime = 0 AND domainId = {$id}) OR (deleteRow = 'Y' AND domainId = {$id})"); However, this is not safe against SQL injection. Could someone help me to make this safe, or tell me how to rebuild this with the ORM. Thanks! 回答1: This would be the query as you had it $result = DB::table('mod_dns_records') ->where('scheduled', 'N') ->where('scheduleTime', 0) ->where('domainId', $id) ->orWhere(

PHP - foreach loop like WHERE clause

时光总嘲笑我的痴心妄想 提交于 2019-12-22 09:22:08
问题 I've been trying to figure this one out but just can't wrap my head around it. I have these xml objects that I'm working with: SimpleXMLElement Object ( [@attributes] => Array ( [product_category_id] => 13463 [name] => A Athletic Wear [path] => A Athletic Wear [thumburl_front] => REPLACE_DOMAIN_WITH/images/publishers/440/ProductCategories/A_Athletic_Wear/80.gif ) ) SimpleXMLElement Object ( [@attributes] => Array ( [product_category_id] => 13475 [name] => A Accessories [path] => A Accessories

When mysql WHERE clause is empty, return all rows

江枫思渺然 提交于 2019-12-22 08:38:02
问题 $randomvariable=$_GET['randomvariable']; $search="SELECT * from objects WHERE transactiontype='$randomvariable' order by id DESC"; Now if $randomvariable is empty (nothing), I would like it to return all rows. Currently if it's empty it returns nothing, because it basically searches for nothing from all of the rows. 回答1: $randomvariable = ESACPE_MYSQL_STRING($_GET['randomvariable']); $search = "SELECT * FROM objects " . (empty($randomvariable) ? "" : "WHERE transactiontype='$randomvariable' "

C# predicate list passed to Linq Where clause

流过昼夜 提交于 2019-12-22 04:36:11
问题 I have a long Linq Where clause that I would like to populate with a predicate list. List<Expression<Func<Note, bool>>> filters = new List<Expression<Func<Note, bool>>>(); filters.Add(p => p.Title != null && p.Title.ToLower().Contains(searchString)); filters.Add(p => p.Notes != null && p.Notes.ToLower().Contains(searchString)); filters.Add(GlobalSearchUser((List < User > users = new List<User>() { p.user1, p.user2, p.user3, p.user4 }), searchString)); notes = dataAccess.GetList<Note>(pn => pn

SQL update where in set of data

断了今生、忘了曾经 提交于 2019-12-22 03:25:43
问题 +------------------+ | id1 | id2 | bool | +------------------+ | 1 | 1 | F | | 1 | 2 | F | | 2 | 1 | F | +------------------+ UPDATE table_name SET bool = T WHERE (id1, id2) IN ((1,1),(2,1)) --Need work here So basically I want to select where the conditions of (id1, id2) = (value1, value2). Similar to the statement below: WHERE id1 = value1 AND id2 = value2 however in set of values in an array. Is this possible? Thanks in advance EDIT: I'm using SQL server 2008. I'm sorry if it wasn't too

SQL update where in set of data

回眸只為那壹抹淺笑 提交于 2019-12-22 03:25:23
问题 +------------------+ | id1 | id2 | bool | +------------------+ | 1 | 1 | F | | 1 | 2 | F | | 2 | 1 | F | +------------------+ UPDATE table_name SET bool = T WHERE (id1, id2) IN ((1,1),(2,1)) --Need work here So basically I want to select where the conditions of (id1, id2) = (value1, value2). Similar to the statement below: WHERE id1 = value1 AND id2 = value2 however in set of values in an array. Is this possible? Thanks in advance EDIT: I'm using SQL server 2008. I'm sorry if it wasn't too