替换 SQLite SQL 中的 Left 命令 [英] Replacement for Left command in SQLite SQL

查看:13
本文介绍了替换 SQLite SQL 中的 Left 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询在 MS Access、MySQL 和 SQL Server 中运行良好,但是当我尝试在 SQLite 中使用它时出现错误:

I have the following query that works fine in MS Access, MySQL and SQL Server but when I try to use it in SQLite I get an error:

("附近:语法错误:

我在 SQLite 的任何文档中都找不到 Left 命令,所以我想它不存在,但是我如何才能让它工作.

I can't find the Left command in any documentation of SQLite so I guess it isn't there but how could I get it to work then.

SELECT 
    Left(fldcall, 3) AS Group1, 
    Mid(fldcall, 4, 1) AS Group2, 
    tblcalls.*, 
    tblzip.fldcity
FROM 
    tblcalls 
LEFT JOIN 
    tblzip ON tblcalls.fldzipcode = tblzip.fldzipcode;

推荐答案

您可以使用 substr() 函数:

SELECT substr(fldcall, 1, 3) AS Group1,
       substr(fldcall, 4, 1) AS Group2,
       tblcalls.*,
       tblzip.fldcity
FROM tblcalls
LEFT JOIN tblzip USING (fldzipcode);

这篇关于替换 SQLite SQL 中的 Left 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆