php - mysql View 或查询显示不同日期的数据?

标签 php mysql view

我有一个 mySQL View ,它可以提供其他表的总计。像这样的东西: 表1:

ID | Parameter1 | Parameter2 | ValidFrom | ValidUntil

表 2:

ID | Parameter3 | Parameter4 | ValidFrom | ValidUntil

View :

SumOfParameter1 | SumOfParameter2 | SumOfParameter3 | SumOfParameter4

问题是我想实现一种方法,使 View 中的数据与数据有效的时间段相对应。例如,如果 Table1 中的一行在 01-2011 到 03-2011 期间有效,Table2 中的一行在 01-2011 到 02-2011 期间有效,另一行从 02-2011 到 03-2001 有效,我的 View 将如下所示:

SumOfParameter1 | SumOfParameter2 | SumOfParameter3 | SumOfParameter4 | 01-2011  
SumOfParameter1 | SumOfParameter2 | SumOfParameter3 | SumOfParameter4 | 02-2011  
SumOfParameter1 | SumOfParameter2 | SumOfParameter3 | SumOfParameter4 | 03-2011

我知道我可以使用 PHP 中的查询并指定我想要的日期来执行此操作,但是是否可以按照我上面提到的方式在 View 中执行此操作?

最佳答案

尝试:

SELECT Parameter1, Parameter2, Parameter3, Parameter4 
FROM table1, table2 
ORDER BY ValidUntil 
GROUP BY ValidUntil

关于php - mysql View 或查询显示不同日期的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5971579/

相关文章:

mysql - 添加字符串而不是结果 0 作为 mysql SUM 的结果

mysql - 如何从 SHOW ERROR MySQL 获取消息和错误代码

mysql - 使用 UNION 在 VIEW 内级联 WHERE 子句

php - 获取错误 [Doctrine\DBAL\DBALException] 请求未知的数据库类型点,Doctrine\DBAL\Platforms\MySQL57Platform 可能不支持它

php - 检查数据库、返回消息和发送电子邮件的函数

php - 在一个循环中执行两条 PDO 语句

magento - 如何获取特定产品的浏览/点击

android - 添加 "Elevation"到View时TextView被隐藏

php - 获取多维数组校验和的最简洁方法是什么?

php - curl_exec 导致 php 脚本停止执行任何操作