case

SQL case when 语句学习

随声附和 提交于 2020-04-06 20:07:07
刚刚同时跑来问我一个sql语句顿时,一看我有点蒙,因为之前没有用过,所以在这里写下学习笔记加深印象。 语法如下: CASE value WHEN [compare-value01] THEN result01 [WHEN [compare-value02] THEN result01 ...] [ELSE result] END 此sql语句我认为有点像条件语句。 意思是: 条件一,当字段value的值等于"compare-value"时,赋值为result01; 条件二,当字段value的值等于"compare-value"时,赋值为result02; ... 条件N,,赋值为result02; 结束 这么说肯定感觉很抽象,上实例,一看就明白了。 usersa表及数据如下图 样例1查询SQL select *, (CASE username WHEN "李四" THEN "四" WHEN "张三" THEN "三" ELSE 'more' END )as "Column" FROM usersa; 查询结果图 样例2查询SQL select sex, count(case username when "李四" then "李四" end) as "李四", count(case username when "张三" then "张三" end) as "张三" from

Sql Query for increase item value price for multiple item

老子叫甜甜 提交于 2020-03-02 03:24:39
问题 I want to write Sql Query for increase item price by percentage. Scenario is :- In table, I have 3 coloumn : ID, Item-Name, Price Example : If item-Name is T-shirt, Increase price by 10% item-Name is Jins , Increase price by 50% item-Name is top , Increase price by 5% 回答1: If you are looking to update the table you can do conditional update. update table_name set price = case when `Item-Name` = 'T-shirt' then price+( (price*10) /100 ) when `Item-Name` = 'Jins' then price+( (price*50) /100 )

Sql Query for increase item value price for multiple item

耗尽温柔 提交于 2020-03-02 03:21:21
问题 I want to write Sql Query for increase item price by percentage. Scenario is :- In table, I have 3 coloumn : ID, Item-Name, Price Example : If item-Name is T-shirt, Increase price by 10% item-Name is Jins , Increase price by 50% item-Name is top , Increase price by 5% 回答1: If you are looking to update the table you can do conditional update. update table_name set price = case when `Item-Name` = 'T-shirt' then price+( (price*10) /100 ) when `Item-Name` = 'Jins' then price+( (price*50) /100 )

Erlang if、case、guard和函数

这一生的挚爱 提交于 2020-03-01 13:28:44
Erlang 函数、if、case、guard 每节排版顺序:伪代码,说明文字,案例 函数 伪代码 %单一语句的的函数 function_name(Param1, Param2, ..., ParamN) -> Expression1, Expression2, ..., ExpressionN. %多语句的函数,其中每条语句的参数个数应该是一样的 function_name(Param11, Param12, ..., Param1N) -> Expression11, Expression12, ..., Expression1N; function_name(Param21, Param22, ..., Param2N) -> Expression21, Expression22, ..., ExpressionN2; ... function_name(ParamN1, ParamN2, ..., ParamNN) -> ExpressionN1, ExpressionN2, ..., ExpressionNN; 函数的名称是一个基元。一个函数的头包括名字,随后是一对括号,在里面包含多个形式的参数或者没有参数。在Erlang中,函数参数的数量叫做元数。使用箭头(->)来分隔函数头和函数主体。 Erlang函数是由分号分隔开的一个或者多个语句组成的,最后用句点来结束

Select options: jQuery, Case and show/hide form fields

我是研究僧i 提交于 2020-01-29 09:32:51
问题 What is the most efficient way of showing/hiding form fields based on the value of a select control? I have one select control and three input fields, which show/hide based upon what type of business you work for. <select id="business-type"> <option value="1">Sole Trader</option> <option value="2">Partnership</option> <option value="3">Public Sector</option> <option value="4">Public Limited Company (Plc)</option> <option value="5">Charity</option> </select> // This should appear if you are a

Select options: jQuery, Case and show/hide form fields

谁说我不能喝 提交于 2020-01-29 09:31:26
问题 What is the most efficient way of showing/hiding form fields based on the value of a select control? I have one select control and three input fields, which show/hide based upon what type of business you work for. <select id="business-type"> <option value="1">Sole Trader</option> <option value="2">Partnership</option> <option value="3">Public Sector</option> <option value="4">Public Limited Company (Plc)</option> <option value="5">Charity</option> </select> // This should appear if you are a

Using case statement to get weekly count of total orders, cancelled orders and % of cancelled orders

北城以北 提交于 2020-01-25 09:00:26
问题 first time poster and just looking for some guidance on writing a case statement. I'd like to pull the following from a single table total orders by week cancelled orders by week % of orders cancelled I did some reading on case statements, but couldn't find exactly what I was looking for. I assume the case statement would be something along the lines of "case when order = 'cancelled' THEN count orders", but I also know that's wrong, so just looking for some assistance. Thanks in advance! -ET

Usage ROLLBACK TO SAVEPOINT with condition

我的未来我决定 提交于 2020-01-24 13:22:24
问题 Is it possible to ROLLBACK TO SAVEPOINT with CASE? My query is BEGIN; SAVEPOINT my_savepoint; INSERT INTO DPoint (uuid) VALUES ('5547f4b7-00b3-4aac-8ceb-c9ca163a0214') ON CONFLICT (uuid) DO NOTHING; WITH ins1 AS (INSERT INTO Point (latitude, longitude, srid) VALUES (37.251667, 14.917222, 4326) RETURNING id), ins2 as (INSERT INTO SPoint (idPt, uuiddpt) VALUES ((SELECT id FROM ins1), '5547f4b7-00b3-4aac-8ceb-c9ca163a0214') RETURNING id), ins3 as (INSERT INTO Distance (idSpt, uuiddpt) VALUES (

Can I have multiple boolean expressions in a searched case sql statement?

北城余情 提交于 2020-01-24 10:54:11
问题 I'm trying to create a searched case sql statement based on a number of boolean expressions. For example select CASE a = b OR c = d OR e = f OR g = h THEN 'x' ELSE 'y' END from table_name I keep getting the following error: Incorrect syntax near '='. Am I doing something that's inherently wrong/illegal in sql, or is this something I can fix? If it is fixable, how can I do it? Thanks! 回答1: select CASE when ( a = b OR c = d OR e = f OR g = h ) THEN 'x' ELSE 'y' END from table_name The format is

Case statement with where condition in SQL

会有一股神秘感。 提交于 2020-01-17 06:16:09
问题 I am trying to write a CASE statement in SQL. The DB structure is as follows: ============================================== tender_id | file_no | subject ============================================== 150001 16/41 Against Shipment 150005 16/42 Pending 150008 16/43 Shipment Clause 1500081 16/43 NULL or Empty 1500082 16/43 NULL or Empty ============================================== I am trying to write a CASE statement which shows the subject. The criteria is if Subject is NULL or EMPTY then