Question

Hi i'm trying to create the following construct.

enter image description here

Like you may can see i have 2 Columns "Tag" and "Angebot"

My "Tag"column will have a fixed number of rows (foreach weekday 1 row)
where "Angebot" will contains a List of items foreach row from "Tag" (so i will get 7 List's)

i can't throw them in one big list and group them by "Tag" because there non such Property

so how would you solve this problem

Était-ce utile?

La solution

Forgive me if my German is rusty but I believe what you are trying to do is group by day of week correct? I don't know what database you are using so I will demonstrate in MySQL:

It looks like you have your layout decided upon so I will focus on the functional data queries in SQL. Based on your description, I am assuming a reasonable DDL. I hope you don't mind the English translation.

First our offer (angebot) table:

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

Now here is a detail query on the table by day number (Tagesnummer). This one is for last month (Feb-2014)

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)

Example Output:

+---------+-----------+---------------------+-------------------+---------+--------+
| 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...

Here is a summary total of offer amounts by day for Feb-2014:

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)

Example output:

+---------+-----------+---------------+
| 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)

The DDL and queries in this post have been tested. Let me know if you need the data :)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top