conditional

How sum with case conditional statement works in sql

五迷三道 提交于 2019-12-30 07:31:47
问题 The other day, I gave an answer to this question but then other user solved that problem with sum + case conditional statement to add one edge condition in result. So, the question came to my mind, how statement sum(case when jobname = 'Analyst' then 1 else 0 end) in the below query works select d.* from (select deptno, sum(case when jobname = 'Analyst' then 1 else 0 end) as numAnalysts from employees group by deptno order by numAnalysts asc ) d where rownum = 1;` and return the number of

Conditional column for query based on other columns in MySQL

核能气质少年 提交于 2019-12-30 00:40:34
问题 I'm pretty sure I've seen this somewhere, but I can't find the right terminology so I'm having trouble... Let's say I have a table with user info (let's also assume that it was created by someone who gets paid more than me, so modifying the schema is not an option.) Among the various columns of user info are columns for DOB and job title. I want a query that, based on what is in those columns, will include an extra column called "Real_Title", for example: User_id Job_Title DOB joe_1 manager

Select rows until a total amount is met in a column (mysql)

怎甘沉沦 提交于 2019-12-29 08:12:40
问题 I have seen this issue in SF, but me being a noob I just can't get my fried brain around them. So please forgive me if this feels like repetition. My Sample Table -------------------------- ID | Supplier | QTY -------------------------- 1 1 2 2 1 2 3 2 5 4 3 2 5 1 3 6 2 4 I need to get the rows "UNTIL" the cumulative total for "QTY" is equal or greater than 5 in descending order for a particular supplier id. In this example, for supplier 1, it will be rows with the ids of 5 and 2. Id - unique

Select rows until a total amount is met in a column (mysql)

守給你的承諾、 提交于 2019-12-29 08:12:12
问题 I have seen this issue in SF, but me being a noob I just can't get my fried brain around them. So please forgive me if this feels like repetition. My Sample Table -------------------------- ID | Supplier | QTY -------------------------- 1 1 2 2 1 2 3 2 5 4 3 2 5 1 3 6 2 4 I need to get the rows "UNTIL" the cumulative total for "QTY" is equal or greater than 5 in descending order for a particular supplier id. In this example, for supplier 1, it will be rows with the ids of 5 and 2. Id - unique

Conditional Compilation in assembler (.s) code for iPhone - how?

扶醉桌前 提交于 2019-12-29 07:17:10
问题 I have a few lines of assembler arm code in an .s file. Just a few routines i need to call. It works fine when building for the device, however when i switch to iPhone Simulator i get "no such instruction" errors. I tried to compile parts of the .s file conditionally with what i know: #if !TARGET_IPHONE_SIMULATOR But the assembler doesn't recognize these preprocessor directives (of course) and none of the conditional compilation techniques for assembler that i could remember or find worked,

Why use !== FALSE to check stripos in php?

为君一笑 提交于 2019-12-28 16:42:08
问题 Here is the code I am looking at. foreach ($header as $idx => $field) { if (stripos($field, 'foo') !== false) { $cols['foo'] = $idx; } else if (stripos($field, 'bar') !== false) { $cols['bar'] = $idx; } else if (stripos($field, 'brr') !== false) { $cols['brr'] = $idx; } else if (stripos($field, 'ffo') !== false) { $cols['ffo'] = $idx; } } Sorry, don't know how to format the code prettily either, any tips on that would be appreciated. I am looking at some code written by someone much smarter

Why use !== FALSE to check stripos in php?

跟風遠走 提交于 2019-12-28 16:41:11
问题 Here is the code I am looking at. foreach ($header as $idx => $field) { if (stripos($field, 'foo') !== false) { $cols['foo'] = $idx; } else if (stripos($field, 'bar') !== false) { $cols['bar'] = $idx; } else if (stripos($field, 'brr') !== false) { $cols['brr'] = $idx; } else if (stripos($field, 'ffo') !== false) { $cols['ffo'] = $idx; } } Sorry, don't know how to format the code prettily either, any tips on that would be appreciated. I am looking at some code written by someone much smarter

How to add conditional where clauses in rails

无人久伴 提交于 2019-12-28 13:51:09
问题 I am a rails newbie and am trying to perform a search on a table with rails, and i'm just using my sql knowledge to do this. But this just doesn't seems like rails or ruby even... Is there any better way to do what i'm doing below? (basically, only pass date arguments to sql if they are filled) def search(begin_date=nil, end_date=nil) subject = " and created_at " if !(begin_date.nil? || end_date.nil?) where_part = subject + "BETWEEN :begin_date AND :end_date" else if (begin_date.nil? && end

C conditional operator ('?') with empty second parameter [duplicate]

故事扮演 提交于 2019-12-28 05:35:25
问题 This question already has answers here : ?: ternary conditional operator behaviour when leaving one expression empty (2 answers) Closed 5 years ago . Typically the '?' operator is used in the following form: A ? B : C However in cases where B = A I have seen the following abbreviation A ? : C This surprisingly works. Is it better to leave the second parameter in (style wise), or is their a chance certain compilers won't be able to handle this? 回答1: It is not permitted by the language C (as

Creating a new column based on if-elif-else condition

早过忘川 提交于 2019-12-27 11:54:11
问题 I have a DataFrame df : A B a 2 2 b 3 1 c 1 3 I want to create a new column based on the following criteria: if row A == B: 0 if row A > B: 1 if row A < B: -1 so given the above table, it should be: A B C a 2 2 0 b 3 1 1 c 1 3 -1 For typical if else cases I do np.where(df.A > df.B, 1, -1) , does pandas provide a special syntax for solving my problem with one step (without the necessity of creating 3 new columns and then combining the result)? 回答1: To formalize some of the approaches laid out