case

Creating Column based on WHERE condition

孤街醉人 提交于 2020-06-29 06:43:09
问题 I've the following query: SELECT tn.Date, b1.Name DrBook, b2.Name CrBook, c1.Name DrControl, c2.Name CrControl, l1.Name DrLedger, l2.Name CrLedger, s1.Name DrSubLedger, s2.Name CrSubLedger, p1.Name DrParty, p2.Name CrParty, m1.Name DrMember, m2.Name CrMember, tn.Amount, tn.Narration FROM Transactions tn LEFT JOIN Books b1 ON b1.Id = tn.DrBook LEFT JOIN Books b2 ON b2.Id = tn.CrBook LEFT JOIN ControlLedgers c1 ON c1.Id = tn.DrControl LEFT JOIN ControlLedgers c2 ON c2.Id = tn.CrControl LEFT

Converting a nested decode into equivalent CASE statement (needed for conversion from Oracle to PostgreSQL)

若如初见. 提交于 2020-06-17 13:17:09
问题 I am on Oracle 11.2.0.4. I have a nested DECODE statement that I need to convert into CASE statement. Can someone help on it. I am not sure of how it is done and in fact I don't fully understand the logic of it. If someone can explain what it basically intends to do and what would be the rewritten function using CASE that is Very useful to me. Here is the function...(note: do not worry about table joins , there are 3 tables and one condition etc. please focus on the DECODE and its conversion

Why is this case when not working properly?

别等时光非礼了梦想. 提交于 2020-06-09 04:15:29
问题 if ( item::class == RPG::Weapon ) print "yup" end case item::class when RPG::Item type = 0 when RPG::Weapon type = 1 when RPG::Armor type = 2 else type = 10 end I'm new to Ruby. The if statement runs fine and prints "yup", but the case statement isn't working properly and sets type to 10. Am I blind to something or what? 回答1: Module#=== tests if the argument is an instance of self . item.class can never be an instance of anything but Class, in particular, it will never be an instance of

Switch: Multiple values in one case?

百般思念 提交于 2020-05-25 08:57:21
问题 I have the following piece of code, but yet when I enter "12" I still get "You an old person". Isn't 9 - 15 the numbers 9 UNTIL 15? How else do I handle multiple values with one case? int age = Convert.ToInt32(txtBoxAge.Text); switch (age) { case 1 - 8: MessageBox.Show("You are only " + age + " years old\n You must be kidding right.\nPlease fill in your *real* age."); break; case 9 - 15: MessageBox.Show("You are only " + age + " years old\n That's too young!"); break; case 16-100: MessageBox

Guards vs. if-then-else vs. cases in Haskell

守給你的承諾、 提交于 2020-05-09 17:32:15
问题 I have three functions that find the nth element of a list: nthElement :: [a] -> Int -> Maybe a nthElement [] a = Nothing nthElement (x:xs) a | a <= 0 = Nothing | a == 1 = Just x | a > 1 = nthElement xs (a-1) nthElementIf :: [a] -> Int -> Maybe a nthElementIf [] a = Nothing nthElementIf (x:xs) a = if a <= 1 then if a <= 0 then Nothing else Just x -- a == 1 else nthElementIf xs (a-1) nthElementCases :: [a] -> Int -> Maybe a nthElementCases [] a = Nothing nthElementCases (x:xs) a = case a <= 0

SQL Setting Variable for Current Year Month by Combining two VarChar fields using case statement

ぃ、小莉子 提交于 2020-04-18 05:18:00
问题 I am trying to declare a variable for the current year and month based on a field called YEARMO. It's a 6 character varchar field with the first 4 characters representing the year and the next 2 characters representing the month (ex. February 2018 as 201802). I need the month variable to have a 0 in front of it if is a month that only has one digit (any month before October). Current code returns '20182' and would like it to return '201802'. declare @current_month varchar(6) set @current

Using select in the “ELSE” of a CASE statement gives me ORA-00937: not a single-group group function

吃可爱长大的小学妹 提交于 2020-04-14 07:37:31
问题 When I try to have a select statement using listagg in the ELSE portion of my query, I get ORA-00937 error. Any way around this? select CASE when count(*) = 0 then 'There are no users connected' else (select listagg(osuser, ', ') within group (order by osuser) from (select distinct osuser from v$session) where osuser != 'SYSTEM' and osuser not like 'VMCONFTEST%') end from v$session where username is not null and osuser not like 'VMCONFTEST%'; Even if I replace the select statement with

SQL case when 语句解析

▼魔方 西西 提交于 2020-04-07 07:00:42
一,原始单表(也是从其他博客看到)及其查询后效果。 原始表: 查询后(要求查询后按照洲统计人口): 二,SQL探讨 *初始化insert语如下: INSERT INTO cptable VALUES (NULL ,'中国',600); INSERT INTO cptable VALUES (NULL ,'美国',100); INSERT INTO cptable VALUES (NULL ,'加拿大',100); INSERT INTO cptable VALUES (NULL ,'英国',200); INSERT INTO cptable VALUES (NULL ,'法国',300); INSERT INTO cptable VALUES (NULL ,'日本',250); INSERT INTO cptable VALUES (NULL ,'德国',200); INSERT INTO cptable VALUES (NULL ,'墨西哥',50); INSERT INTO cptable VALUES (NULL ,'印度',250); *SQL查询语句 表达方式A: SELECT SUM(population), CASE country WHEN '中国' THEN '亚洲' WHEN '印度' THEN '亚洲' WHEN '日本' THEN '亚洲' WHEN '美国