MySQL - 更新最后一次出现的字符串(MySQL - Update last occurrence of string)
我有这样一张桌子:
+----------------------------+ | id | name | helper | +----------------------------+ | 1 | user1 | NULL | | 2 | user1 | NULL | | 3 | user1 | NULL | | 4 | user2 | NULL | | 5 | user2 | NULL | +----------------------------+
现在我想更新“user1”的最后一次出现 - 我该怎么做?
这是我现在的示例查询:
UPDATE Table SET helper = 'bob' WHERE name = 'user1' AND helper IS NULL;
但是,这会更新所有“user1”条目。
提前致谢。
I have a table like this:
+----------------------------+ | id | name | helper | +----------------------------+ | 1 | user1 | NULL | | 2 | user1 | NULL | | 3 | user1 | NULL | | 4 | user2 | NULL | | 5 | user2 | NULL | +----------------------------+
Now I want to update the LAST occurrence of "user1" - how do I do that?
This is my example query right now:
UPDATE Table SET helper = 'bob' WHERE name = 'user1' AND helper IS NULL;
However, this updates all the "user1" Entries.
Thanks in advance.
原文:https://stackoverflow.com/questions/24215526
最满意答案
NVM,没有odbc接口,但它是DBI之类的(看到DBI不使用odbc,除了在DBD :: ODBC中)
libdbi - http://libdbi.sourceforge.net/
libdbi在C中实现了一个与数据库无关的抽象层,类似于Perl中的DBI / DBD层。 编写一组通用代码,程序员可以使用此框架利用多个数据库的强大功能和多个同步数据库连接。
为了利用libdbi框架,您需要为特定类型的数据库安装驱动程序。 libdbi正式支持的驱动程序分为libdbi-drivers项目。 当前版本的libdbi(0.8.3)应该适用于任何0.8.x版本的libdbi-drivers。 目前支持以下数据库引擎:
* Firebird/Interbase * FreeTDS (provides access to MS SQL Server and Sybase) * MySQL * PostgreSQL * SQLite/SQLite3
NVM, no odbc interface, but it is DBI like (seeing as DBI doesn't use odbc except in DBD::ODBC)
libdbi - http://libdbi.sourceforge.net/
libdbi implements a database-independent abstraction layer in C, similar to the DBI/DBD layer in Perl. Writing one generic set of code, programmers can leverage the power of multiple databases and multiple simultaneous database connections by using this framework.
In order to utilize the libdbi framework, you need to install drivers for a particular type of database. The drivers officially supported by libdbi are split off into the libdbi-drivers project. The current version of libdbi (0.8.3) is supposed to work with any 0.8.x release of libdbi-drivers. Currently the following database engines are supported:
* Firebird/Interbase * FreeTDS (provides access to MS SQL Server and Sybase) * MySQL * PostgreSQL * SQLite/SQLite3
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我会用 my $dbh = DBI->connect("DBI:mysql:database=abc;host=abc123.name.locale;port=3306", 'foo-man', 'mypa55w0rd'); 但如果您将用户名后面的逗号更改为分号,它可能也会起作用。 I would use my $dbh = DBI->connect("DBI:mysql:database=abc;host=abc123.name.locale;port=33 ...
-
请参阅DBD-mysql ppm信息页面 , 构建日志文件 。 ActiveState尝试在构建之前应用一些本地补丁,但它失败了。 联系他们以解决这个问题。 同时恢复到5.14,其中存在PPM包,或者如果您知道如何,则尝试在您自己的系统上手动构建DBD-mysql。 See DBD-mysql ppm info page, build log file. ActiveState tries to apply some local patches before building, but it fails. ...
-
在运行任何其他语句之前尝试运行db.do(“SET SCHEMA SCHEMA_NAME”) 编辑:正确的语法是:db.do(“ALTER SESSION SET CURRENT_SCHEMA = SCHEMA_NAME”) 这会将您的默认架构更改为您希望在会话期间处理的架构 Try running db.do("SET SCHEMA SCHEMA_NAME") before running any other statements Edit: The correct syntax is : db.do(" ...
-
暂时,尝试在 Windows 之前想象个人计算机的硬件市场。 例如,在那些日子里,每个应用程序都需要有自己的驱动程序。 这意味着如果一台打印机没有WordStar和Lotus 1-2-3的驱动程序,那么它在办公环境中几乎没用。 如果您有一台适用于这两种应用程序的打印机,但您现在也想要哈佛图形的输出怎么办? 您需要确保应用程序本身知道如何处理您的特定打印机。 也就是说, N个应用程序和M打印机意味着需要N × M个驱动程序。 使用Windows,硬件制造商可以为Windows编写驱动程序,只要应用程序知道如何 ...
-
无法捕获DBI错误(Can't catch DBI error)[2023-12-31]
默认的错误处理是: RaiseError => 0 PrintError => 1 PrintWarn => 0 您想要传递PrintError => 0来connect 。 如果你想检查错误: my $dbh = DBI->connect($dsn, $user, $passwd, { RaiseError => 0, PrintError => 0, }); if (!$dbh) { die($DBI::errstr); } 如果您更喜欢抛出异常: my $dbh = eval ... -
Class::DBI 文档告诉您提供自己的db_Main()方法,而不是使用connection() 。 我相信这可能会返回一个标准的DBI句柄,但是Class :: DBI在内部使用了Ima :: DBI。 您可以为此使用单个类,但要镜像您的伪代码: package MyClassLibAlias; use base qw(MyClassLib); sub db_Main { my $self = shift; my ($dsn, $username, $password ...
-
你需要问自己的第一个问题是: 查询应该编码(如果是,编码),还是应该解码(即Unicode代码点)? 这应该基于sqlite_unicode ,但事实并非如此。 这只会影响返回的字符串。 我怀疑DBD :: SQLite与大多数/所有DBD一样,都受到Unicode Bug的影响,这意味着问题的答案是基于字符串存储方式的内部细节。 在UTF-8系统中,它通常“只是工作”,我很惊讶它不在这里。 请尝试 use Encode qw( decode_utf8 ); my $sql = decode_utf8(s ...
-
NVM,没有odbc接口,但它是DBI之类的(看到DBI不使用odbc,除了在DBD :: ODBC中) libdbi - http://libdbi.sourceforge.net/ libdbi在C中实现了一个与数据库无关的抽象层,类似于Perl中的DBI / DBD层。 编写一组通用代码,程序员可以使用此框架利用多个数据库的强大功能和多个同步数据库连接。 为了利用libdbi框架,您需要为特定类型的数据库安装驱动程序。 libdbi正式支持的驱动程序分为libdbi-drivers项目。 当前版本的l ...