case

Checking 2 sql columns and displaying result in 1 column pt2

狂风中的少年 提交于 2020-01-06 04:38:07
问题 I have 2 tables...they are basically the same except for the column name in one of them because they deal with 2 different names, though.. the data I want is in columns that have the same name. Pretty much what I want to do... is .they also need to be distinct so I don't count duplicates... I can get them as separate tables... but I can't get them together.. I need them in 1 column because of how it is sent to the C3 code page and how it reads it... the structure has already been previously

Finding if current row is last row to be selected from database

两盒软妹~` 提交于 2020-01-05 12:46:46
问题 I am selecting list of periods from database. If current row is first row then the period starts with date and I can find the interval between period start like this: SELECT ... CASE WHEN row_number() OVER(ORDER BY r.created_at ASC) = 1 THEN r.created_at - r.created_at::date ELSE NULL END AS period ... FROM mytable r How can I do the same to last row? To find the time between the r.created_at of last row and midnight of its date. I am aware of first and last functions in PostgreSQL (https:/

scala playframework json implicit case class conversion

蹲街弑〆低调 提交于 2020-01-05 12:09:06
问题 I am developing my first Play 2.1 application in Scala. The task I am trying to accomplish is to parse json into 3 different case classes. The problem is - I do not know where to declare all case classes. Each class in it's own file or all in one file. Here is what I've done (it doesn't work, case values are not visible in controller object): File LoginBase.scala package models abstract class LoginBase case class Login(email: String, password: String) extends LoginBase case class RestoreLogin

PostgreSQL crosstab() alternative with CASE and aggregates

我的梦境 提交于 2020-01-05 07:15:32
问题 I want to create a pivot table view showing month on month sum of bookings for every travel_mode . Table bookings : timestamp , bookings , provider_id Table providers : provider_id , travel_mode Pivot table function and crosstab functions are not to be used to do this. So I am trying to use JOIN and CASE. Following is the query: SELECT b.month, (CASE WHEN p.travel_mode=train then b.amount end)train, (CASE WHEN p.travel_mode=bus then b.amount end)bus, (CASE WHEN p.travel_mode=air then b.amount

SUM/COUNT of CASE within CASE in MYSQL

痴心易碎 提交于 2020-01-05 06:51:29
问题 Have below Column in table product : a | b | cat -------------- 2 | 4 | 1 3 | 1 | 1 4 | 4 | 1 2 | 1 | 1 3 | 2 | 1 5 | 3 | 1 8 | 7 | 2 5 | 3 | 2 $sql = "SELECT SUM(CASE WHEN cat = 1 AND a > b THEN 1 else 0 end) as prdplus FROM product "; in above query i am getting value for sum or count of a greater then b which is 3>1 , 2>1 , 3>2 , 5>3 hence output of above query will be : 4 prdplus ------- 4 what i need is count value have only +1 in above count of 4 thats with above query now i need +1

MySQL - Retrieve row value from different table depending on value of row in a table

三世轮回 提交于 2020-01-05 04:32:09
问题 I have a feeling CASE should be used here but I am not sure. I'm trying to take the sex (m/f) from the general table and depending on the sex, get the build from the corresponding table. For example, when the sex is m, the query should know that by going to the males table and selecting the male_build. I put together an output along with a sample query to give an idea of what I'm trying to accomplish: members table member_id | member_name ------------------------ 1 Herb 2 Karen 3 Megan 4

CASE statements in Hive

点点圈 提交于 2020-01-03 17:31:47
问题 Ok, i have a following code to mark records that have highest month_cd in tabl with binary flag: Select t1.month_cd, t2.max_month_cd ,CASE WHEN t2.max_month_cd != null then 0 else 1 end test_1 ,CASE WHEN t2.max_month_cd = null then 0 else 1 end test_2 from source t1 Left join ( Select MAX(month_cd) as max_month_cd From source ) t2 on t1.month_cd = t2.max_month_cd; It seems straight forward to me, but result it return is: month_cd max_month_cd test_1 test_2 201610 null 1 1 201611 201611 1 1

How can I use “OR” condition in MySQL CASE expression?

这一生的挚爱 提交于 2020-01-03 10:56:13
问题 I have a procedure that contains CASE expression statement like so: BEGIN .... WHILE counter < total DO .... CASE ranking WHEN 1 OR 51 OR 100 OR 167 THEN SET project_name = 'alpha'; WHEN 2 THEN SET project_name = 'beta'; WHEN 10 OR 31 OR 40 OR 61 THEN SET project_name = 'charlie'; .... ELSE SET project_name = 'zelta'; END CASE; INSERT INTO project (id, name) VALUES (LAST_INSERT_ID(), project_name); SET counter = counter + 1; END WHILE; END $$ DELIMITER ; When I call the above procedure, cases

How to write SSIS switch/case expression?

怎甘沉沦 提交于 2020-01-03 08:42:32
问题 This is a SQL Server Integration Services (SSIS) expressions question (I'm pretty new to it). I would like to write a switch/case expression in a Derived Column transform - basically the new column can have 5 different possible values, based on the value of an input column. All I got from Google is the (condition) ? (true value) : (false value) technique, but this only provides for two possible values. Does SSIS expressions have a switch/case type expression? I thought of using sequential

How to write SSIS switch/case expression?

…衆ロ難τιáo~ 提交于 2020-01-03 08:42:06
问题 This is a SQL Server Integration Services (SSIS) expressions question (I'm pretty new to it). I would like to write a switch/case expression in a Derived Column transform - basically the new column can have 5 different possible values, based on the value of an input column. All I got from Google is the (condition) ? (true value) : (false value) technique, but this only provides for two possible values. Does SSIS expressions have a switch/case type expression? I thought of using sequential