case

Count the total records containing specific values

纵然是瞬间 提交于 2019-12-09 16:30:14
问题 I have a question and hope you guys can assist me. I have a table containing two columns: type // contains 2 different values: "Raid" and "Hold" authorization // contains 2 different values: "Accepted" or "Denied" I need to make a view that returns values like this: TYPE:RAID ACCEPTED:5 DENIED:7 Basically I want to know how many of the values in TYPE are "Raid" and then how many of them are "Accepted" and "Denied". Thank you in advance!! 回答1: SELECT Type ,sum(case Authorization when 'Accepted

Replace text while keeping case intact in C#

橙三吉。 提交于 2019-12-09 09:44:52
问题 I have a set of sentences i need to use to do a replace, for example: abc => cde ab df => de ... And i have a text where to make the changes. However i have no way to know beforehand case of said text. So, for example, if i have: A bgt abc hyi. Abc Ab df h I must replace and get: A bgt cde nyi. Cde De h Or as close to that as possible, i.e. keep case EDIT: As i am seeing to much confusion about this i will try to clarify a bit: I am asking about a way to keep caps after replacing and i don't

How do I use Group By based on a Case statement in Oracle?

空扰寡人 提交于 2019-12-08 23:45:29
问题 I have an SQL-query where I use Oracle CASE to compare if a date column is less than or greater than current date. But how do I use that CASE -statement in a GROUP BY -statement? I would like to count the records in each case. E.g. select (case when exp_date > sysdate then 1 when exp_date <= sysdate then 2 else 3 end) expired, count(*) from mytable group by expired But I get an error when trying this: ORA-00904 . Any suggestions? 回答1: select (case when exp_date > sysdate then 1 when exp_date

How to write a MYSQL CASE WHEN statement with multiple search conditions?

邮差的信 提交于 2019-12-08 21:03:46
问题 I know languages like PHP has switch case control structure that supports multiple validations in a single case statement like, Switch $x { case 1,2,3: $a = 0; break; case 5,6: $a = 1; break; } Similarly can this be done in MYSQL? I tried below, which really didn't work though :( CASE vc_shape WHEN ('02' OR '51') THEN SET dc_square_1 = dc_square_1 + dc_row_total; WHEN ('06' OR '30' OR 83) THEN SET dc_square_2 = dc_square_2 + dc_row_total; ..... ..... ELSE BEGIN END; END CASE; Any ideas how

python - Simulating 'else' in dictionary switch statements

会有一股神秘感。 提交于 2019-12-08 19:13:48
问题 I'm working on a project which used a load of If, Elif, Elif, ...Else structures, which I later changed for switch-like statements, as shown here and here. How would I go about adding a general "Hey, that option doesn't exist" case similar to an Else in an If, Elif, Else statement - something that gets executed if none of the If s or Elif s get to run? 回答1: You could catch the KeyError error that ensues when a value is not found in the map, and return or process there a default value. For

Perl regex replace in same case

我的未来我决定 提交于 2019-12-08 18:06:22
问题 If you have a simple regex replace in perl as follows: ($line =~ s/JAM/AAA/g){ how would I modify it so that it looks at the match and makes the replacement the same case as the match for example: 'JAM' would become 'AAA' and 'jam' would become 'aaa' 回答1: $line =~ s/JAM/{$& eq 'jam' ? 'aaa' : 'AAA'}/gie; 回答2: Unicode-based solution: use Unicode::UCD qw(charinfo); my %category_mapping = ( Lu # upper-case Letter => 'A', Ll # lower-case Letter => 'a', ); join q(), map { $category_mapping

Invalid column name error in WHERE clause, column selected with CASE

狂风中的少年 提交于 2019-12-08 16:05:02
问题 I have a (rather complicated) SQL statement where I select data from lots of different tables, and to cope with a bad legacy data structure, I have a couple of custom columns that get their values based on values from other columns. I have currently solved this with CASE statements: SELECT ..., CASE channel WHEN 1 THEN channel_1 WHEN 2 THEN channel_2 ... ELSE 0 END AS ChannelValue, CASE channelu WHEN 1 THEN channelu_1 WHEN 2 THEN channelu_2 ... ELSE '0' END AS ChannelWithUnit, ... FROM ... -

Why does R 3.6.0 return FALSE when evaluating the expression (“Dogs” < “cats”)?

半腔热情 提交于 2019-12-08 15:07:50
问题 I have some complicated code, but instead of showing you that, I am going to extract the essence of the problem. Evaluate: "dogs" < "cats" … This should evaluate to FALSE and it does in R 3.6. Evaluate: "Dogs" < "cats" … This should evaluate to TRUE because the ASCII code for "D" is 68 and the ASCII code for "c" is 99. Since 68 < 99, "Dogs" < "cats" should evaluate to TRUE , but it does not in R 3.6.0. However, when I tried using the Console window on the https://datacamp.com website, the

How to pattern match a class with multiple argument lists?

北战南征 提交于 2019-12-08 14:37:59
问题 Consider this class: class DateTime(year: Int, month: Int, day: Int)(hour: Int, minute: Int, second: Int) how would the unapply method look like, if I would like to match against something like: dt match { case DateTime(2012, 12, 12)(12, _, _) => // December 12th 2012, 12 o'clock /* ... */ } I tried this: def unapply(dt: DateTime) = Some((dt.year, dt.month, dt.day),(dt.hour, dt.minute, dt.second)) But that didn't really work. 回答1: Case classes match (and do their other nifty things) only on

How to add to Where clause depending on parameter value

≡放荡痞女 提交于 2019-12-08 14:02:14
问题 I have an sql query that I am wanting to run and want to add something to the where clause if I mark a parameter as true. I didn't think I would need to have the same sql statement twice, but can't find a way to do this. This is what I want. DECLARE @getShipped VARCHAR = 'false'; SELECT DISTINCT Serial_No INTO #Serials FROM Part_v_Container_Change2 AS CC WHERE Change_Date <= @dateEnding *** AND IF @getShipped = 'true' THEN CC.Container_Status = 'Shipped' *** Have tried if statements and case