56,679
社区成员
发帖
与我相关
我的任务
分享
SELECT #语句1:正规
gc.Column11 AS Season,
g.GoodsName AS Category,
gc.Column3 AS Buyer
FROM
sam_ba_goods g
INNER JOIN sam_ba_goodscustom gc ON g.GoodsId = gc.GoodsId
INNER JOIN sam_ba_item i ON g.GoodsId = i.GoodsId
WHERE
gc.Column4 IS NOT NULL
AND g.EntId = 1002
and gc.Column11 = '2017_冬'
GROUP BY
gc.Column11,
g.GoodsName,
gc.Column3;
SELECT #语句2:按别名Group By
gc.Column11 AS Season,
g.GoodsName AS Category,
gc.Column3 AS Buyer
FROM
sam_ba_goods g
INNER JOIN sam_ba_goodscustom gc ON g.GoodsId = gc.GoodsId
INNER JOIN sam_ba_item i ON g.GoodsId = i.GoodsId
WHERE
gc.Column4 IS NOT NULL
AND g.EntId = 1002
and gc.Column11 = '2017_冬'
GROUP BY
Season,
Category,
Buyer
SELECT #语句1:按别名Group By
gc.Column11 AS Season,
g.GoodsName AS Category,
gc.Column3 AS Buyer,
gc.Column5 AS Price,
i.ItemId AS ItemId,
i.BorrowedTimes
FROM
sam_ba_goods g
INNER JOIN sam_ba_goodscustom gc ON g.GoodsId = gc.GoodsId
INNER JOIN sam_ba_item i ON g.GoodsId = i.GoodsId
WHERE
gc.Column4 IS NOT NULL
AND g.EntId = 1002
GROUP BY #按别名Group By
Season,
Category,
Buyer,
ItemId
order by Season,
Category,
Buyer,
ItemId;
SELECT #语句2:正规
gc.Column11 AS Season,
g.GoodsName AS Category,
gc.Column3 AS Buyer,
gc.Column5 AS Price,
i.ItemId AS ItemId,
i.BorrowedTimes
FROM
sam_ba_goods g
INNER JOIN sam_ba_goodscustom gc ON g.GoodsId = gc.GoodsId
INNER JOIN sam_ba_item i ON g.GoodsId = i.GoodsId
WHERE
gc.Column4 IS NOT NULL
AND g.EntId = 1002
GROUP BY
gc.Column11,
g.GoodsName,
gc.Column3,
i.ItemId
order by Season,
Category,
Buyer,
ItemId;
+----------+------------+-----------+
| Season | Category | Buyer |
+----------+------------+-----------+
| 2017_冬 | 配饰S | 叶铭卉 |
| 2017_冬 | 配饰S | 吴燕群 |
| 2017_冬 | 羽绒服Y | 周鸿 |
| 2017_冬 | 配饰S | 罗云 |
+----------+------------+-----------+
4 rows in set, 1 warning (0.00 sec)
mysql> show warnnings;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'warnn
ings' at line 1
mysql> select 1 as id from(select 1 as id union all select 2 as id) a group by id;
+----+
| id |
+----+
| 1 |
| 1 |
+----+
2 rows in set, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+---------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------+
| Warning | 1052 | Column 'id' in group statement is ambiguous |
+---------+------+---------------------------------------------+