pandas equivalent of np.where

Try: (df[‘A’] + df[‘B’]).where((df[‘A’] < 0) | (df[‘B’] > 0), df[‘A’] / df[‘B’]) The difference between the numpy where and DataFrame where is that the default values are supplied by the DataFrame that the where method is being called on (docs). I.e. np.where(m, A, B) is roughly equivalent to A.where(m, B) If you wanted a … Read more

Conditional WHERE clause in SQL Server

Try this SELECT DateAppr, TimeAppr, TAT, LaserLTR, Permit, LtrPrinter, JobName, JobNumber, JobDesc, ActQty, (ActQty-LtrPrinted) AS L, (ActQty-QtyInserted) AS M, ((ActQty-LtrPrinted)-(ActQty-QtyInserted)) AS N FROM [test].[dbo].[MM] WHERE DateDropped = 0 AND ( (ISNULL(@JobsOnHold, 0) = 1 AND DateAppr >= 0) OR (ISNULL(@JobsOnHold, 0) != 1 AND DateAppr != 0) ) You can read more about conditional WHERE … Read more

SELECTING with multiple WHERE conditions on same column

You can either use GROUP BY and HAVING COUNT(*) = _: SELECT contact_id FROM your_table WHERE flag IN (‘Volunteer’, ‘Uploaded’, …) GROUP BY contact_id HAVING COUNT(*) = 2 — // must match number in the WHERE flag IN (…) list (assuming contact_id, flag is unique). Or use joins: SELECT T1.contact_id FROM your_table T1 JOIN your_table … Read more

SQL server ignore case in a where expression

In the default configuration of a SQL Server database, string comparisons are case-insensitive. If your database overrides this setting (through the use of an alternate collation), then you’ll need to specify what sort of collation to use in your query. SELECT * FROM myTable WHERE myField = ‘sOmeVal’ COLLATE SQL_Latin1_General_CP1_CI_AS Note that the collation I … Read more

How to write a SQL DELETE statement with a SELECT statement in the WHERE clause?

You need to identify the primary key in TableA in order to delete the correct record. The primary key may be a single column or a combination of several columns that uniquely identifies a row in the table. If there is no primary key, then the ROWID pseudo column may be used as the primary … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)