V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
la0wei
V2EX  ›  MySQL

oracle 临时表 二次查询 子查询

  •  
  •   la0wei · 319 天前 · 778 次点击
    这是一个创建于 319 天前的主题,其中的信息可能已经有所发展或是发生改变。

    借版问一个 oracle 的问题,表大概示例如下

    产品 销售日期 价格
    可乐 2023.6.5 2.5
    雪碧 2023.6.5 2.5
    牛奶 2023.6.6 10
    咖啡 2023.6.6 12

    …… 程序要查询数据库生成可乐的销售记录 select * from table where 产品='可乐'

    但是 1 月呢?可以加一个时间的限制

    and SELLDATE>=to_date(1 月初) and SELLDATE<to_date(1 月末),变成

    select * from table where 产品='可乐' and SELLDATE>=to_date(1 月初) and SELLDATE<to_date(1 月末) 以此类推,可以得到每个月份的数据。

    但是,假设可乐(产品)没有索引,查询时间很长,那么每查一个月份都要来这么一次,实在太慢了。

    目前有一个思路是临时表,还有别的路径吗。

    搜索得知 oracle 有子查询,不过子查询只有一个输出结果吧,select * from table where 产品='可乐'的输出需要多次用到,该怎么处理?

    2 条回复    2023-06-05 17:00:02 +08:00
    DOMO
        1
    DOMO  
       319 天前
    group by ?
    la0wei
        2
    la0wei  
    OP
       319 天前
    @DOMO 非常感谢,这个也进入待选项,我研究下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1020 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:22 · PVG 03:22 · LAX 12:22 · JFK 15:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.