case

MYSQL LEFT JOIN optimization with CASE

无人久伴 提交于 2019-12-12 13:46:39
问题 I spent some time trying to get working this SELECT with CASE but I failed... (thank to that I'm using COLASCE() now) How could I optimize this SELECT by using CASE/IF sentences? Is this a fast way to query from different tables selected by a field? SELECT a.folderid, a.foldername, a.contenttype, COALESCE(b.descriptor, c.descriptor, d.descriptor, e.descriptor, f.descriptor) as descriptor FROM t_folders a LEFT JOIN t_files b ON a.contenttype = 'file' AND a.contentid = b.fileid LEFT JOIN t

How to use conditional columns values in the same select statement?

*爱你&永不变心* 提交于 2019-12-12 11:11:51
问题 I have something like ( COMPLEX_EXPRESSION_N stands for a long subquery) select ID_Operation, FirstCheck = CASE WHEN (COMPLEX_EXPRESSION_1)= 0 then 0 else 1 end, SecondCheck = CASE WHEN (COMPLEX_EXPRESSION_2)= 0 then 0 else 1 end, ThirdCheck = CASE WHEN (COMPLEX_EXPRESSION_3)= 0 then 0 else 1 end, AllChecksOk = Case WHEN (FirstCheck + SecondCheck + Third CHeck = 3) Then 'OK' Else 'No' End from AllOperationsTable Is it possible to use FirstCheck, SecondCheck, ThirdCheck as I did in the

MySQL CASE WHEN THEN empty case values

你说的曾经没有我的故事 提交于 2019-12-12 10:54:21
问题 SELECT CASE WHEN age IS NULL THEN 'Unspecified' WHEN age < 18 THEN '<18' WHEN age >= 18 AND age <= 24 THEN '18-24' WHEN age >= 25 AND age <= 30 THEN '25-30' WHEN age >= 31 AND age <= 40 THEN '31-40' WHEN age > 40 THEN '>40' END AS ageband, COUNT(*) FROM (SELECT age FROM table) t GROUP BY ageband This is my query. These are the results: However if the table.age doesn't have at least 1 age in a category, it will just flat out ignore that case in the result. Like such: This data set didnt have

Inconsistent results with NEWID() and PERSISTED computed column

China☆狼群 提交于 2019-12-12 10:45:12
问题 I am getting odd results when using NEWID() in combination with a persistent computed column. Am I using some function wrong? Not using persisted when creating the column, and therefore calculating values when selecting them, will return correct values. Updating the column (col1) will also return correct values. DECLARE @test TABLE ( Col1 INT, Contains2 AS CASE WHEN 2 IN (Col1) THEN 1 ELSE 0 END PERSISTED) INSERT INTO @test (Col1) VALUES (ABS(CHECKSUM(NEWID()) % 5)), (ABS(CHECKSUM(NEWID()) %

Case insensitivity in selectors?

流过昼夜 提交于 2019-12-12 08:43:20
问题 I am trying to use jQuery for XML processing. One of the problem that I am stuck with jQuery is it is case insensitive in processing tags and attribute. For e.g., consider the following code: $("<div><Book ISBN='1234'>Some title</Book></div>").html() the output we get is: <book isbn="1234">Some title</book> whereas the output i am looking for is: <Book ISBN="1234">Some title</Book> Any possibility? (Note that "B" is capital letter, and the whole attribute name "ISBN" is also in capital case,

Bash case statement

二次信任 提交于 2019-12-12 07:14:39
问题 I'm trying to learn case as I was to write a fully functional script. I'm starting off with the below #!/bin/sh case $@ in -h|--help) echo "You have selected Help" ;; -B|-b) echo "You have selected B" ;; -C|-c) echo "You have selected C" ;; *) echo "Valid Choices are A,B,C" exit 1 ;; esac I want to use two of these options: ./getopts.sh -h -c But i get this result Valid Choices are A,B,C Please can you help out and let me know what I'm doing wrong? I want to build a script that will do

using CASE WHEN in SQL Statement

六眼飞鱼酱① 提交于 2019-12-12 06:59:43
问题 I have to display information by comparing data in two ID columns, one column has 'ALL' and numbers as ID's while the other has only numbers in it as ID's. My problem is, I cannot compare character and number columns with a number column. So I am using CASE WHEN. If the value is 'ALL' then display 'ALL' in the output, else display name for the matching records. Here is the code: CASE WHEN secorg.org_id = 'ALL' THEN 'ALL' WHEN secorg.org_id = progmap.org_id THEN secorg.org_name END AS org_name

using > in case statement causes syntax error

情到浓时终转凉″ 提交于 2019-12-12 06:14:46
问题 Using the below code gives me a incorrect syntax near '>' the data in the Long field looks like this: Review Body 3, Review body 6, Aprentice, I've been going around in cirlces for hours traying to sort this, is it becasue I'm using a text function (Right) in a calc. SELECT TOP 1000 [Id] ,[Short] ,[Long] ,CASE ISNUMERIC(RIGHT( grade.Long , 1 )) WHEN cast(RIGHT( shiftname.Long , 1 )as int) > 4 THEN 'Qualified' ELSE 'Unqualified' END as Grade FROM [RosterPro_Live].[dbo].[lookup_PostGrade] as

How to check a SQL CASE with multiple conditions?

白昼怎懂夜的黑 提交于 2019-12-12 05:39:40
问题 I have two tables. Accounts ACC and FinancialTrans FT The FinancialTrans table is as follows: AcctID TransTypeCode DateOfTrans 123 TOLL 2016-06-06 00:00:00.000 123 TOLL 2016-06-02 00:00:00.000 123 TOLL 2016-04-28 00:00:00.000 123 PYMT 2016-03-11 00:00:00.000 123 TOLL 2015-12-22 00:00:00.000 123 TOLL 2015-12-22 00:00:00.000 The requirement is: When any Accounts have NO 'TOLL' or 'PYMT' in the last 2 years print 'Flag' SELECT ACC.Field1 ,ACC.Field2 ,ACC.Field3 ,ACC.Field4 ,CASE WHEN (SELECT Max

How to use an array in case?

一笑奈何 提交于 2019-12-12 05:01:55
问题 How can I use an array in the case of a switch? This doesn't work and always take the default (3): switch ($my_array) { case array('george','paul'): $id = 1; break; case array('paul','max'): $id = 2; break; case array('eric'): $id = 3; break; //default default: $id = 3; break; } 回答1: Your example should work, according to the PHP manual on array operators: $a == $b : TRUE if $a and $b have the same key/value pairs. Since switch/case uses weak comparison, arrays are compared by using the ==