标题:GROUP BY 分组问题
取消只看楼主
shulei521521
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2007-8-7
 问题点数:0 回复次数:2 
GROUP BY 分组问题
SELECT T_Goods_Day_Sale.goods_id, SUM(T_Goods_Day_Sale.qty) AS Expr1,
SUM(T_Goods_Day_Sale.ramt) AS Expr2, T_Goods.goods_name,
T_Goods_Day_Sale.ramt - T_Goods.inprc * T_Goods_Day_Sale.qty AS MaoLi,
(T_Goods_Day_Sale.ramt - T_Goods.inprc * T_Goods_Day_Sale.qty)
/ T_Goods_Day_Sale.ramt AS MaoLiLv
FROM T_Goods INNER JOIN
T_Goods_Day_Sale ON T_Goods.Goods_id = T_Goods_Day_Sale.goods_id
WHERE (T_Goods_Day_Sale.sale_date BETWEEN @sale_dateA AND @sale_dateB)
ORDER BY T_Goods_Day_Sale.qty DESC, T_Goods_Day_Sale.ramt DESC, MaoLiLv DESC,
MaoLi DESC
group by good_names
查询的字段都要保留
搜索更多相关主题的帖子: GROUP 分组 
2007-08-17 08:17
shulei521521
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2007-8-7
得分:0 
SELECT T_Goods.goods_name, SUM(T_Goods_Day_Sale.qty) AS qty1,
SUM(T_Goods_Day_Sale.ramt) AS ramt1, SUM(T_Goods_Day_Sale.ramt)
- SUM(T_Goods.inprc * T_Goods_Day_Sale.qty) AS MaoLi,
(SUM(T_Goods_Day_Sale.ramt) - SUM(T_Goods.inprc * T_Goods_Day_Sale.qty))
/ SUM(T_Goods_Day_Sale.ramt) AS MaoLiLv
FROM T_Goods INNER JOIN
T_Goods_Day_Sale ON T_Goods.Goods_id = T_Goods_Day_Sale.goods_id
WHERE (T_Goods_Day_Sale.sale_date BETWEEN @sale_dateA AND @sale_dateB)
GROUP BY T_Goods.goods_name
ORDER BY qty1 DESC, ramt1 DESC, maoli DESC, maolilv DESC

2007-08-17 10:18
shulei521521
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2007-8-7
得分:0 
问题已经解决

2007-08-17 10:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-163340-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.160601 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved