case

Clojure range-case macro

天涯浪子 提交于 2019-12-23 09:57:35
问题 In the book "The Scheme Programming Language, 4th Edition", by R. Kent Dybvig, on page 86, the author has written a define-syntax (Scheme macro) for a case statement that accepts ranges for its conditions. I thought I would try this in Clojure. Here is the result. How can I improve this? I use :ii , :ie , :ei , and :ee for the range operators, indicating inclusive-inclusive, inclusive-exclusive, exclusive-inclusive, and exclusive-exclusive, respectively. Is there a better choice? I chose to

SQL update rows in column using CASE statement

给你一囗甜甜゛ 提交于 2019-12-23 09:52:03
问题 I have two tables, Users and #TempTable (which is a subset of Users). I would like to update a column, IsActive, in the Users table. I would like to set IsActive = 1 if a user that is in #TempTable is also in the Users table, and set IsActive = 0 otherwise. Getting the users from Users that are NOT in #TempTable (IsActive should be set to 0 for these users): -- (Users \ #TempTable) U (#TempTable \ Users) SELECT u.UserName FROM Users u WHERE (u.UserName) NOT IN (SELECT t.[User Name] FROM

Case statement to determine if I should union

我的梦境 提交于 2019-12-23 07:57:54
问题 I currently want to do some sort of conditional union. Given the following example: SELECT age, name FROM users UNION SELECT 25 AS age, 'Betty' AS name Say I wanted to only union the second statement if the count of 'users' was >=2 , otherwise do not union the two. In summary I want to append a table with a row if the table only has 2 or more values. 回答1: You could use an ugly hack something like this, but I think Tim's answer is better: SELECT age, name FROM users UNION ALL SELECT 25 AS age,

Sorting table by different cols, depending on what happens to another column

谁说我不能喝 提交于 2019-12-23 04:28:10
问题 This is my first time I'm asking a question, and English is not my native language. I apologize for any misspelling or misbehaving beforehand. Now to my question: I have a table looking like this. (image 1) 1. Every booked time is half an hour long 2. There are always booking_date, hour and minute 3. Some rows have got delivery_date, some hasn’t yet 4. Delivery_date are always AFTER booking_date unordered table If the day being printed out is for example (2018-12-01), I want the table to be

Ruby: passing array items into a case statement

本小妞迷上赌 提交于 2019-12-23 03:46:08
问题 I am attempting to pass an array into a case statement so I can read the array elements as commands. Unfortunately, it seems that it is not working and the program jumps to the else statement. def input_console() quit = 0 puts "Tell me what you want to do:" loop do print "\n >>> " input = gets.chomp sentence = input.split case sentence when sentence[0] == "go" && sentence[1] == "to" puts sentence[2] when sentence[0] == "quit" quit = 1 else puts "No le entiendo Senor..." end break if quit == 1

awk set elements in array

对着背影说爱祢 提交于 2019-12-23 02:52:18
问题 I have a large .csv file to to process and my elements are arranged randomly like this: xxxxxx,xx, MLOCAL , MREMOTE , 33222 , 56 , 22/10/2012 , 18/10/2012 xxxxxx,xx, MREMOTE , MLOCAL , 33222 , 56 , 22/10/2012 , 18/10/2012 xxxxxx,xx, MLOCAL , 341993 , 22/10/2012 xxxxxx,xx, MREMOTE , 9356828 , 08/10/2012 xxxxxx,xx, LOCAL , REMOTE , 19316 , 15253 , 22/10/2012 , 22/10/2012 xxxxxx,xx, REMOTE , LOCAL , 1865871 , 383666 , 22/10/2012 , 22/10/2012 xxxxxx,xx, REMOTE , 1180306134 , 19/10/2012 where

Case Statement with different data type

梦想的初衷 提交于 2019-12-22 11:24:47
问题 I am trying to return SLA days for particular conditions. However for a specific condition I want it to return a different data type. Current code is as follows: SELECT CASE WHEN fourthlevel.case_type IN ('Complaint') THEN (SELECT COUNT (*) FROM work_days1 WHERE work_days1.business_date > fourthlevel.cdate AND work_days1.business_date <= COALESCE (fourthlevel.close_date, SYSDATE)) WHEN fourthlevel.case_type IN ('Enquiry') THEN (SELECT COUNT (*) FROM work_days1 WHERE work_days1.business_date >

Oracle Conditional where clause

↘锁芯ラ 提交于 2019-12-22 11:23:00
问题 is there any way to write query with following functionality, add where clause as a conditional way, select e.emp_id, emp.admin_user from employees e if emp.admin != 'Y' then query run with where clause else query run without where clause ? 回答1: Using a CASE expression in the WHERE clause should do the trick. When you say you don't need the where clause if condition is not met, then all you want is a condition like WHERE 1 = 1 , i.e. when condition is not met then return all rows. So, you

SQL WHERE depending on day of week

荒凉一梦 提交于 2019-12-22 11:21:29
问题 I have a requirement to check records up to differing dates, depending on which day of the week it is currently. On a Friday I need for it to look at the entire next week, until Sunday after next. On any other day it should check the current week, up until the coming Sunday. I have the below currently but it's not working due to syntax error. Is it possible to do a CASE WHEN inside a WHERE clause? WHERE T0.[Status] IN ('R','P') AND CASE WHEN DATEPART(weekday,GETDATE()) = '5' THEN T0.[DueDate]

Common Lisp case and quoted elements

让人想犯罪 __ 提交于 2019-12-22 10:45:26
问题 I'm writing a dungeon crawler game in CL, and I'm having trouble with the case form. Two things: Common Lisp complains Duplicate keyform QUOTE in CASE statement (make-instance 'cl-rogue:tile tile-type 'wall) should print as "#", but the object prints as " " no matter which tile-type I use. The code: (in-package :cl-user) (defpackage :cl-rogue (:use :common-lisp) (:export :*rows* :*cols* :*levels* :tile :tile-type :tile-contents :tile-hidden :tile-locked :tile-closed :main)) (in-package :cl