首页 \ 问答 \ MySQL - 更新最后一次出现的字符串(MySQL - Update last occurrence of string)

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
更新时间:2022-03-02 06:03

最满意答案

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

相关问答

更多
  • 我会用 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编写驱动程序,只要应用程序知道如何 ...
  • 默认的错误处理是: 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)