像 mysql 问题中那样进行转换和旋转
我希望有人能给我带来光明。
很长一段时间以来,我一直在尝试在一次查询中按周、按天和按年获取一些销售结果,但没有机会。
我找到了一种可以帮助我的语法,但在 mysql 中不起作用。
TRANSFORM
Sum(Cantidad) AS Ventas
SELECT
Producto, Cantidad
FROM
Pedidos
WHERE
Fecha Between #01-01-1998# And #12-31-1998#
GROUP BY
Producto
ORDER BY
Producto
PIVOT
DatePart("m", Fecha)
我真正的查询是这个:
select sum(orders.final_price) AS total
, orders.id_comercial
, vendedores.nombre
from orders
, vendedores
WHERE orders.id_comercial = vendedores.id
AND DATE(orders.date_purchased) = DATE(NOW())
GROUP BY orders.id_comercial
我真的很欣赏一些想法,可能在西班牙已经很晚了;)
我查询的结果是这个:
total id_comercial nombre
740.83 24 AITOR ANGULO
2069.37 29 FERNANDO I
482.05 32 JOSE ANDRES
961.32 33 ALBERTO FERNANDEZ -CANTABRIA-
908.66 34 GONZALO
49.54 38 LUIS LOPEZ
4082.42 39 JULEN DEL CURA
1512.87 43 ALBERTO POBLACION
1268.91 44 MASSIMO
3269.08 45 JOSE RAMON BURGA
56.49 47 EMPRESA
2791.65 48 MARCO MORILLO
1445.57 61 TINO
869.73 63 SONIA
1052.02 381 DAVID ARIAS
真的谢谢大家。
I hope someone could show me the light.
I'm trying since a long time to get the result o some sales by week, day and year in one query with no chance.
I have found a syntax that can help me but dont work in mysql.
TRANSFORM
Sum(Cantidad) AS Ventas
SELECT
Producto, Cantidad
FROM
Pedidos
WHERE
Fecha Between #01-01-1998# And #12-31-1998#
GROUP BY
Producto
ORDER BY
Producto
PIVOT
DatePart("m", Fecha)
My real query is this one:
select sum(orders.final_price) AS total
, orders.id_comercial
, vendedores.nombre
from orders
, vendedores
WHERE orders.id_comercial = vendedores.id
AND DATE(orders.date_purchased) = DATE(NOW())
GROUP BY orders.id_comercial
I really will appreciate some ideas, it's maybe to late in teh night here in spain ;)
The result of my query is this one:
total id_comercial nombre
740.83 24 AITOR ANGULO
2069.37 29 FERNANDO I
482.05 32 JOSE ANDRES
961.32 33 ALBERTO FERNANDEZ -CANTABRIA-
908.66 34 GONZALO
49.54 38 LUIS LOPEZ
4082.42 39 JULEN DEL CURA
1512.87 43 ALBERTO POBLACION
1268.91 44 MASSIMO
3269.08 45 JOSE RAMON BURGA
56.49 47 EMPRESA
2791.65 48 MARCO MORILLO
1445.57 61 TINO
869.73 63 SONIA
1052.02 381 DAVID ARIAS
Really thnx to all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如,这将为您提供当天、7 天和年初至今的总计,
仅供参考
date(concat(year(now()),'-01-01'))
为您提供今年的第一天但是如果你想要一个数据透视表,那么
MySQL(或任何其他像样的 RDBMS)就没有相当于 Access 运算符 TRANSFORM 的功能,它会自动从数据中生成动态数量的列。
For example, this will give you the day, 7-day and year-to-date totals
FYI
date(concat(year(now()),'-01-01'))
gives you the first day of the current yearBut if you want a pivot table, then
There is no MySQL (or any other decent RDBMS for that matter) equivalent of the Access operator TRANSFORM, which automatically produces a dynamic number of columns from the data.