where-clause

CodeIgniter - Grouping where clause

只谈情不闲聊 提交于 2019-12-11 03:59:55
问题 I have this following query for CodeIgniter: $q = $this->db->where('(message_from="'.$user_id.'" AND message_to="'.$this->auth_model->userdata['user_id'].'")') ->or_where('(message_from="'.$this->auth_model->userdata['user_id'].'" AND message_to="'.$user_id.'")') ->get('messages'); I want to write this query with completely active record. I have tried something like this: $from_where = array('message_from'=>$user_id, 'message_to'=>$this->auth_model->userdata['user_id']); $to_where = array(

T-SQL Group by with a where clause

懵懂的女人 提交于 2019-12-11 02:08:57
问题 Masterid CC CLA DES NLCLA NLDES ------------------------------------- 53006141 CN 0 0 1 1 53006141 US 1 1 1 1 53006141 UK 1 1 0 0 53006142 US 1 1 0 0 53006142 UK 1 1 0 0 53006143 CN 0 0 1 1 53006143 US 1 1 0 0 53006143 UK 1 1 0 0 From the above data I need to produce a list of MasterIds where there is CC = US or CC = CN and NLCLA = 1 and NLDES = 1 The output should be 53006141 53006143 There has to be both CN and US under a MasterID. Can someone help me to do this in SQL please? 回答1: You can

WHERE Column IN from parameter in DB2 over SSIS

流过昼夜 提交于 2019-12-11 00:58:37
问题 I want to do the following command in a SSIS Package to DB2. UPDATE MyTable SET Col1 = ?, Col2 = ? WHERE Col3 IN (?) The Parameters are connected and the package is finished successfully but no row is updated. The Col3 contains values like 123 , 452 and so on and the third parameter is a string with a content like 345,432,456,432,667,123,456 . What have I to change to be able to update the rows? I tried it with the following. In SQL Server it would work but in DB2 not. UPDATE MyTable SET Col1

mysql using user-defined variable in where clause

你离开我真会死。 提交于 2019-12-10 23:16:34
问题 sql query: select u.username, @total_subscribers:=( select count(s.id) from subscribers as s where s.suid = u.uid ) as total_subscribers from users as u where @total_subscribers > 0 if i remove where @total_subscribers > 0 query will show all users and their total subscribers but i want to show only those users who have at least 1 subscriber... after i add the where clause and use the defined variable i get an empty result set. 回答1: You can do it with group by and having : select u.username,

Zend Framework: Re-use WHERE clause returned from Zend_Db_Select::getPart()

人走茶凉 提交于 2019-12-10 19:59:57
问题 I have a SELECT object which contains a WHERE. I can return the WHERE using getPart(Zend_Db_Select::WHERE) , this returns something like this: array 0 => string "(clienttype = 'agent')" 1 => string "AND (nextpayment < (NOW() - INTERVAL 1 DAY))" This array seems pretty useless as I cannot do this with it $client->update(array("paymentstatus" => "lapsed"), $where); Or even put it into another SELECT object. Is there a way of getting a more useful representation of the WHERE statement from the

Multiple Where conditions

时间秒杀一切 提交于 2019-12-10 19:26:33
问题 Having trouble getting this syntax right: SELECT DISTINCT id FROM metadata WHERE (meta_key = 'school' AND meta_value = 'Some School') AND WHERE (meta_key = 'hidden' AND meta_value = '1') Its failing at line 4... UPDATED: Table looks like this: meta_id - id - meta_key - meta_value 1 1 school Some School 1 2 1 hidden 0 3 2 school Some School 2 4 2 hidden 1 5 3 school Some School 3 6 3 hidden 0 7 4 school Some School 4 8 4 hidden 0 9 5 school Some School 5 10 5 hidden 1 UPDATED: I have a related

Find the most recent date in a result set

拥有回忆 提交于 2019-12-10 18:37:11
问题 I'm working on a query where I need to look at patient vitals (specifically blood pressure) that were entered when a patient visited a clinic. I'm pulling results for the entire year of 2015, and of course there are certain patients who visited multiple times, and I need to only see the vitals that were entered at the most recent visit. Another slight twist is that systolic and diastolic pressures are entered separately, so I end up with results like: Patient ID Name DOB Test Results Date ---

C# Beginner: Where has my IList.Where() method gone?

♀尐吖头ヾ 提交于 2019-12-10 18:09:20
问题 I've got another simple one (I think) that's stumping me. I have written a method in one of my controls that gets the latest version of a file in a CMS given it's filename (i.e. regardless of what folder the file resides in). I found it useful enough that I thought I'd chuck it in my CMSToolbox class, but when I do this I can no longer use the Where() method of a FileManager class provided by the CMS (which returns a list). Here's a simplified example of my class: using System; using System

Rails 4.x how to query boolean value with activerecord?

梦想与她 提交于 2019-12-10 17:52:48
问题 I a boolean "guessed" on my model "perks" and I am trying to get all customers that have perks where guessed is true. My first guess was this: @customer = Customer.includes(:perks).where('perks.guessed = true') But that gives me an SQL-exception: "no such column: true" A bit of googling gave me this thread: Rails - how to search based on a boolean field? (MySQL error) So I tried: @customer = Customer.includes(:perks).where('perks.guessed = 1') No luck... Also tried: @customer = Customer

Building dynamic where condition in SQL statement

老子叫甜甜 提交于 2019-12-10 17:19:51
问题 I want to build custom Where condition based on stored procedure inputs, if not null then I will use them in the statement, else I will not use them. if @Vendor_Name is not null begin set @where += 'Upper(vendors.VENDOR_NAME) LIKE "%"+ UPPER(@Vendor_Name) +"%"' end else if @Entity is not null begin set @where += 'AND headers.ORG_ID = @Entity' end select * from table_name where @where But I get this error An expression of non-boolean type specified in a context where a condition is expected,