case-when

State machine; why only last state is working?

假装没事ソ 提交于 2019-12-12 15:37:32
问题 I have a state machine with 6 states(3 main states). Only the last state is working but the first 2 doesn't(out of 3).Only the last state is working. I found out the problem, when I remove the debounce circuit it works, but I need the debouncing circuit. I got the debouncing circuit from the internet. I would be glad if someone can help. type SM_STATES is (state_column_1, scan_col_1, state_column_2, scan_col_2, state_column_3, scan_col_3); signal my_state : SM_STATES := state_column_1; Below

Collate language codes into one combined locale code using CASE WHEN, and count the number of times the combined locale code occurs on a date

China☆狼群 提交于 2019-12-11 21:21:12
问题 Learning about CASE WHEN, and I've come across a use case when I see multiple locale codes in Analytics. This is a much simpler question that is much easier to answer and read, than my prior question that was posted. Examples are: en-us (english US) en-au (english australia) en-br (english brazil) es-es (spanish spain) es-419 (spanish-latam) pt-br (portuguese brazil) pt-pt (portugal) How do I aggregate these in BigQuery so that instead of counting distinct values, I can count the number of

Combining two counts with joins in one query

两盒软妹~` 提交于 2019-12-11 19:00:05
问题 Ok - hoping someone can help as I'm struggling here. Have tried using sum(case when), count(*), subqueries with no success. Essentially I have two queries I am trying to combine into one, grouped by the same parameter. The queries: Query 1: SELECT u.username, count(*) as 'Total' FROM log1 L1 JOIN users u on u.userref = L1.userref WHERE L1.date between @FromDate and @ToDate GROUP BY u.username ORDER BY u.username Query 2: SELECT u.username, count(*) as 'Total' FROM log2 L2 LEFT JOIN users u on

Using an 'IN' predicate with CASE statements in the WHERE clause for SQL Server

杀马特。学长 韩版系。学妹 提交于 2019-12-11 14:43:58
问题 Here's a SQL query that works absolutely fine: DECLARE @IncludePTO AS CHAR SET @IncludePTO = 'Y' SELECT HQCO.HQCo, HQCO.Name, PREH.PRDept, PREH.Craft, HRRM.PositionCode, PRTH.Employee, PREH.LastName, PREH.FirstName, SUM(PRTH.Hours) AS Hrs FROM PREH INNER JOIN HRRM ON PREH.PRCo = HRRM.HRCo AND PREH.Employee = HRRM.HRRef INNER JOIN PRTH ON PREH.PRCo = PRTH.PRCo AND PREH.Employee = PRTH.Employee INNER JOIN HQCO ON PRTH.PRCo = HQCO.HQCo WHERE (dbo.PRTH.PREndDate BETWEEN '1/1/2012 00:00:00' AND '1

SQL case when set variable

天涯浪子 提交于 2019-12-11 11:53:28
问题 I am trying to set 2 declared variable with case when blocks Here's my code: DECLARE @like bit,@dislike bit if exists ( select * ,@like = (CASE WHEN likeordislike = 1 THEN 'true' ELSE 'false' END) ,@dislike=(CASE WHEN likeordislike = 0 THEN 'true' ELSE 'false' END) from likeordislike ) But when I execute query throws errors: Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '='. Everything is ok? Couldn't understand 回答1: if (select count(*) from likeordislike where user = @user and

np.where on multiple variables

拈花ヽ惹草 提交于 2019-12-11 07:40:06
问题 I have a data frame with: customer_id [1,2,3,4,5,6,7,8,9,10] feature1 [0,0,1,1,0,0,1,1,0,0] feature2 [1,0,1,0,1,0,1,0,1,0] feature3 [0,0,1,0,0,0,1,0,0,0] Using this I want to create a new variable (say new_var) to say when feature 1 is 1 then the new_var=1, if feature_2=1 then new_var=2, feature3=1 then new_var=3 else 4. I was trying np.where but though it doesn't give me an error, it doesn't do the right thing - so I guess a nested np.where works on a single variable only. In which case,

case statement in stored procedure

北城余情 提交于 2019-12-11 05:55:42
问题 I have this stored procedure, its working CREATE PROCEDURE myrange() BEGIN SET @start = 0; PREPARE stmt FROM ' SELECT firstname FROM peoples ORDER BY id LIMIT ?,1 INTO @name'; WHILE @start < 5 DO EXECUTE stmt USING @start; CASE WHEN @name = 'Ana' THEN INSERT INTO mytable (log) VALUES('yes'); ELSE INSERT INTO mytable (log) VALUES('no'); END CASE; SET @start = @start + 1; END WHILE; END; but, if I delete from this procedure, this piece of code: ELSE INSERT INTO mytable (log) VALUES('no');

How do I conditionally aggregate values in projection part of pandas query?

这一生的挚爱 提交于 2019-12-11 05:23:42
问题 I currently have a csv file with this content: ID PRODUCT_ID NAME STOCK SELL_COUNT DELIVERED_BY 1 P1 PRODUCT_P1 12 15 UPS 2 P2 PRODUCT_P2 4 3 DHL 3 P3 PRODUCT_P3 120 22 DHL 4 P1 PRODUCT_P1 423 18 UPS 5 P2 PRODUCT_P2 0 5 GLS 6 P3 PRODUCT_P3 53 10 DHL 7 P4 PRODUCT_P4 22 0 UPS 8 P1 PRODUCT_P1 94 56 GLS 9 P1 PRODUCT_P1 9 24 GLS When I execute this SQL query: SELECT PRODUCT_ID, MIN(CASE WHEN DELIVERED_BY = 'UPS' THEN STOCK END) as STOCK, SUM(CASE WHEN ID > 6 THEN SELL_COUNT END) as TOTAL_SELL

Phone number lookups using incoming numbers of varying lengths, with or without prefixes

心已入冬 提交于 2019-12-11 03:17:13
问题 Systems: -Call Center phone system: incoming calls accompanied by the source number, aka Caller ID, aka "ANI" -SQL Server 2005 - the "data warehouse" which stores customer phone numbers ([cANI]), cust names, location, etc. in a table [CustDataByANI] -Stored Procedure - call center software passes the Caller ID (aka ANI) to a SP as a parameter which uses it to perform a presently simple SELECT statement on the CustDataByANI table....WHERE [cANI] = @ANI. This works wonderfully, provided the

SQL Server: difference in days for two dates in separate rows

不想你离开。 提交于 2019-12-11 02:37:35
问题 I am using SQL Server 2012 and working an a report currently that is asking me to find the difference in days between two dates. Basically, for a particular ReportID , I'm trying to find the difference in days between the ( ReportCompletedDate when the ReportType = 'PaperReceived' ) - ( ReportCompletedDate when the ReportType = 'Form Completed' ) I tried to give some records below... ReportID ReportType ReportCompletedDate ------------------------------------------------- 450 PaperReceived 9