-1

我想做一个 SQL 查询,给出一个月的总订单价值(我的选择)。例如,我想知道 2010 年 1 月产生了多少钱。

    Table = ordrar

    ordernumber date
    1           2010-01-02
    2           2010-01-03
    3           2010-01-03
    4           2010-01-04
    5           2010-01-05
    6           2010-02-17
    7           2010-02-18

    Table = orderrader

    rownummer   ordernumber price   amount
    1           1           8624    3
    2           1           4794    2
    3           1           8755    3
    4           2           7803    1
    5           2           8987    3
    6           3           4575    3
    7           3           8747    1
    8           4           5439    3
    9           4           8624    1
    10          5           9574    2
    11          6           4794    1
    12          7           9102    2

谢谢你。

4

2 回答 2

1

也许是这样的:

SELECT
    SUM(price*amount) AS Total
FROM
    orderrader
    JOIN ordrar
        ON orderrader.ordernumber =ordrar.ordernumber
WHERE
    YEAR(date)=2010
    AND MONTH(date)=1
于 2012-05-14T07:14:06.977 回答
0
select sum(price*amount) as money from ordrar A join orderrader B on A.ordernumber = B.ordernumber where A.date between '01-01-2010' and '31-01-2010'
于 2012-05-14T07:27:18.643 回答