首页 \ 问答 \ SQL ORDER BY“IF”(SQL ORDER BY “IF”)

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
更新时间:2023-08-15 14:08

最满意答案

链接的重复问题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 ...
  • 您可以按生日分组并查看多次出现的所有生日: 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 ...
  • 看起来你正在回答你自己的问题:)你也可以随时调用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 ...
  • 你需要使用不同的。 试试以下 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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。