Mysql SELECT 值比较?

标签 mysql

这样的表格:

-----------------------------
id    pid    key    value
-----------------------------
1      3    all     120
2      3    today   180
3      9    all     200
4      9    today   150
5      9    others   0
-----------------------------

如何

select * from table if all(120) < today(180) and if they have same pid(3)

我希望结果应该是:

---------------------------
id    pid    key    value
---------------------------
1      3     all    120
2      3    today   180

最佳答案

假设您想要相同 pid 存在另一个具有所有 < 今天的条目的所有条目

select t from table t where exists( 
    select * from table t2 where t.all < t2.today and t.pid = t2.pid
)

关于Mysql SELECT 值比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38337523/

相关文章:

mysql - MySQL中的排名函数

php - iphone 开发 - 使用 PHP 和 Mysql 在真实设备上测试应用程序

mysql - Mysql 语法错误

mysql - 在单个资源中连接到多个 mysql 数据库

mysql - 向 mysql 数据库插入新行

mysql - 我如何查看 mysql 转储的进度?

Php Codeigniter,验证空值

mysql - 如何使用alter table创建两个主键

mysql - 如何在同一张表中找到相似的记录?

mysql - 错误代码 1215 : Foreign key error : Why am I getting this?