SQL ORDER BY“IF”(SQL ORDER BY “IF”)
如果列不包含数字,我想按标题排序,如果第一个字母是数字,我想按标题* 1排序。
ORDER BY if(title REGEXP '^[0-9]+'=0,title,title*1) ASC
什么是假的?
I want to order by title if column doesn't contain number and by title*1 if its first letter is a number.
ORDER BY if(title REGEXP '^[0-9]+'=0,title,title*1) ASC
What is false there ?
原文:https://stackoverflow.com/questions/44250239
最满意答案
链接的重复问题APC显示了一个工作示例,但澄清您有两个问题。 第一个是非致命的,只是你没有
EOF
,正如Rembunator指出的那样(尽管它在答案中的位置错误)。更重要的是,虽然你没有终止
;
在您的查询中,因此SQL * Plus不会执行它 - 它只是退出而没有输出。如果您在SQL * Plus命令提示符下键入原始查询,它会让您在另一个提示符处等待输入,如果您再次点击return,则返回正常提示符,而不实际执行查询:
SQL> select billcycle from bc_run 2 where billcycle not in (50,16) 3 and control_group_ind is null 4 and billseqno=6043 5 SQL>
您可能还需要至少一些输出格式。 所以这应该工作:
v_bc=`sqlplus -s /@bscsprod <<EOF set pagesize 0 select billcycle from bc_run where billcycle not in (50,16) and control_group_ind is null and billseqno=6043; EOF`
The duplicate question APC linked to shows a working example, but to clarify you have two problems. The first is non-fatal and is just that you don't have
EOF
, as Rembunator pointed out(though it's in the wrong place in that answer).More importantly though you don't have a terminating
;
in your query, so SQL*Plus won't execute it - it just exits with no output.If you typed your original query in as the SQL*Plus command prompt it would leave you at a further prompt waiting for input, and then go back to a normal prompt if you just hit return again, without actually executing the query:
SQL> select billcycle from bc_run 2 where billcycle not in (50,16) 3 and control_group_ind is null 4 and billseqno=6043 5 SQL>
You also probably want at least some formatting of the output. So this should work:
v_bc=`sqlplus -s /@bscsprod <<EOF set pagesize 0 select billcycle from bc_run where billcycle not in (50,16) and control_group_ind is null and billseqno=6043; EOF`
相关问答
更多-
linux/Unix Sql 命令[2023-10-30]
看你需要了``Unix不是开源系统``学习的话还是去研究Linux比较好 在命令行输入的SQL意思是执行SQL客户端,USE,SELECT,之类的SQL指令会被SQL客户端解析.. SQL指令有很多~~建议楼主到W3School去看 -
当您在shell脚本中使用sqlplus时,最好使用静默模式“sqlplus -s”登录以抑制登录消息,并删除sql提示符“sql>”。 此外,您需要更改一些变量,如: 标题 - 它不会显示查询结果的头部(要更精确的列名称) set heading off 反馈 - 在查询选择后它不会返回行数。 set feedback off verify - 用于显示值,以防您有替换变量 set verify off 上面列出的列默认为ON,因此如果你想要一个干净的显示(只是结果),最好将它们关闭,如果你的sq ...
-
据我所知,MsSQL DATETIME数据类型有一个奇怪的分辨率,因为毫秒被舍入到0,3或7,所以看起来你已经陷入了其中一个案例。 您可能想要使用DATETIME2数据类型(从SqLServer2008开始,我猜),其分辨率为100ns。 小时差异应取决于服务器时区。 As far as I know a MsSQL DATETIME data type, has a strange resolution, as milliseconds are rounded to 0, 3 or 7, so it ap ...
-
链接的重复问题APC显示了一个工作示例,但澄清您有两个问题。 第一个是非致命的,只是你没有EOF ,正如Rembunator指出的那样 (尽管它在答案中的位置错误) 。 更重要的是,虽然你没有终止; 在您的查询中,因此SQL * Plus不会执行它 - 它只是退出而没有输出。 如果您在SQL * Plus命令提示符下键入原始查询,它会让您在另一个提示符处等待输入,如果您再次点击return,则返回正常提示符,而不实际执行查询: SQL> select billcycle from bc_run 2 w ...
-
尝试这个 WHERE ColA LIKE '%2[%]%' Try this WHERE ColA LIKE '%2[%]%'
-
尝试这样的事情: UNIX_TIMESTAMP(STR_TO_DATE(mydate, '%M %e %Y %h:%i%p')) Try something like this: UNIX_TIMESTAMP(STR_TO_DATE(mydate, '%M %e %Y %h:%i%p'))
-
在这里粘贴答案,因为我之前无法回答,因为我的帐户太新了。 好的语法错误最终是为UPDATE不喜欢的列字段添加引号。 删除那些给了我NULL值但查询运行。 然后我发现我必须在SELECT函数中包装时间戳转换。 这是我成功转换所有字段的代码: UPDATE wp_6222_postmeta SET meta_value = (SELECT UNIX_TIMESTAMP(STR_TO_DATE(meta_value`,'%m/%d/%Y'))) WHERE meta_key='wpcf-end-date' Pa ...
-
Sql重复记录查询(Sql duplicate record query)[2023-09-15]
您可以按生日分组并查看多次出现的所有生日: SELECT count(1) as frequency, dob FROM students GROUP BY dob HAVING frequency > 1; You can group by birthdays and look at all the birthdays that occur more than once: SELECT count(1) as frequency, dob FROM students GROUP BY dob HAVIN ... -
今天的SQL查询[重复](SQL query today [duplicate])[2023-12-25]
看起来你正在回答你自己的问题:)你也可以随时调用php作为日期,你不需要两次调用数据库: http://php.net/manual/de/function.date.php Looks like you are answering your own question :) you can always call php for the date as well, there you don't need to call the DB tw ... -
避免SQL查询中的重复行(Avoid duplicate rows in SQL query)[2021-08-13]
你需要使用不同的。 试试以下 SELECT distinct products.idProduct, sku, description, listPrice, smallImageUrl, isBundleMain, rental, visits FROM products, categories_products WHERE products.idProduct=categories_products.idProduct AND categories_products.idCateg ...