| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 763 人关注过本帖
标题: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
快速回复:GROUP BY 分组问题
数据加载中...
 
   



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

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