1

嗨,我正在尝试创建以下构造。

在此处输入图像描述

就像您可能看到的那样,我有 2 列“标签”和“Angebot”

我的“标签”列将有固定数量的行(foreach weekday 1 row)
,其中“Angebot”将包含来自“Tag”的每一行的项目列表(所以我将获得 7 个列表)

我不能把它们放在一个大列表中并按“标签”对它们进行分组,因为没有这样的属性

那么你将如何解决这个问题

4

1 回答 1

1

如果我的德语生疏了,请原谅我,但我相信你要做的是按星期分组对吗?我不知道您使用的是什么数据库,所以我将在 MySQL 中演示:

看起来你已经决定了你的布局,所以我将专注于 SQL 中的功能数据查询。根据您的描述,我假设一个合理的 DDL。我希望你不介意英文翻译。

首先我们的报价(angebot)表:

CREATE TABLE
offer
(
  `id`      bigint AUTO_INCREMENT,
  `created` DATETIME             ,
  `from`    VARCHAR(64)          ,
  `item`    VARCHAR(64)          ,
  `amount`  DECIMAL(8,2)          ,
  PRIMARY KEY (id)
);

现在这里是按天数(Tagesnummer)对表进行的详细查询。这是上个月的(2014 年 2 月)

SELECT
         DAYOFWEEK(created) AS `tag_num`,
         DAYNAME(created)   AS `tag`    ,
         `created`                      ,
         `from`                         ,
         `item`                         ,
         `amount`
FROM
         `offer`
WHERE
         `created` >= '2014-02-01'
AND      `created`  < '2014-03-01'
ORDER BY
         DAYOFWEEK(created)

示例输出:

+---------+-----------+---------------------+-------------------+---------+--------+
| tag_num | tag       | created             | from              | item    | amount |
+---------+-----------+---------------------+-------------------+---------+--------+
|       1 | Sunday    | 2014-02-23 13:23:10 | Ivor Quinn        | B6C 5J9 |  91.12 |
|       1 | Sunday    | 2014-02-23 05:21:33 | Ray Robbins       | T2P 4T2 |  13.58 |
|       1 | Sunday    | 2014-02-23 16:31:47 | Craig Orr         | C2R 1I8 |  59.48 |
|       1 | Sunday    | 2014-02-23 13:23:10 | Ivor Quinn        | B6C 5J9 |  91.12 |
|       1 | Sunday    | 2014-02-23 05:21:33 | Ray Robbins       | T2P 4T2 |  13.58 |
|       1 | Sunday    | 2014-02-23 16:31:47 | Craig Orr         | C2R 1I8 |  59.48 |
|       2 | Monday    | 2014-02-10 05:50:36 | Dale Estes        | H9V 2L3 |  63.03 |
|       2 | Monday    | 2014-02-24 06:45:23 | Damian Vincent    | T8T 6E4 |   5.02 |
|       2 | Monday    | 2014-02-10 05:50:36 | Dale Estes        | H9V 2L3 |  63.03 |
|       2 | Monday    | 2014-02-24 06:45:23 | Damian Vincent    | T8T 6E4 |   5.02 |
|       3 | Tuesday   | 2014-02-11 14:20:17 | Oscar Trevino     | F2L 0T3 |  60.22 |
|       3 | Tuesday   | 2014-02-11 05:45:39 | Hilel Cline       | N4M 3V2 |  40.45 |
etc...

以下是 2014 年 2 月按天计算的总报价总额:

SELECT
         DAYOFWEEK(created) AS `tag_num`,
         DAYNAME(created)   AS `tag`    ,
         SUM(`amount`)
FROM
         `offer`
WHERE
         `created` >= '2014-02-01'
AND      `created`  < '2014-03-01'
GROUP BY
         DAYOFWEEK(created)

示例输出:

+---------+-----------+---------------+
| tag_num | tag       | SUM(`amount`) |
+---------+-----------+---------------+
|       1 | Sunday    |        328.36 |
|       2 | Monday    |        136.10 |
|       3 | Tuesday   |        141.12 |
|       4 | Wednesday |         89.38 |
|       6 | Friday    |        169.33 |
|       7 | Saturday  |          1.76 |
+---------+-----------+---------------+
6 rows in set (0.00 sec)

本文中的 DDL 和查询已经过测试。如果您需要数据,请告诉我:)

于 2014-03-21T03:46:47.387 回答