首页 > 解决方案 > 统计每种产品在一天内销售的产品

问题描述

我的查询有问题。想象一下,我有 10 个产品(product1、product2、product3),今天(08/16/2021),我正在销售 15 个“product1、2 个 product2 和 5 个 product3。我需要现在每天销售多少个产品,并且每天都能得到它们。

告诉我我的课程是否足够好,以及我可以使用什么查询或代码。

@Entity(tableName = "stock_products")
data class StockProducts (

    @PrimaryKey(autoGenerate = false)
    val id: String,

    @ColumnInfo(name = "timestamp")
    val timestamp: String,

    @ColumnInfo(name = "productName")
    val orderList: List<ProductInfo>
)

标签: androidkotlinandroid-room

解决方案


数据库的设计应满足您的需求。如果您不想添加仅包含日期的额外列,则可以计算今天 00:00 的时间戳并进行查询“Select orderList where timestamp > $todayTimestamp”

此外,时间戳不应该是字符串。


推荐阅读