计算枚举类型列上的唯一行数以在 mysql 中再输出两列
我有以下 mysql 表:
Item Name Listing Fee Listing Type
watch $0.20 LISTED
watch $0.20 LISTED
watch $0.30 SOLD
glasses $0.50 LISTED
glasses $0.50 LISTED
glasses $0.50 LISTED
glasses $1.00 SOLD
我需要的是下面由 SQL 分组的输出:
Item Name Total Fee Total Listed Total Sold
watch $0.70 2 1
glasses $2.50 3 1
规则是每个“项目名称”将具有多个列表记录,其中定义了费用和列表类型。可能有两种“列表类型”[LISTED & LISTED]。卖]。
我想在表上运行查询并生成类似于提到的输出的摘要。
谢谢 维基百科
I have following mysql table:
Item Name Listing Fee Listing Type
watch $0.20 LISTED
watch $0.20 LISTED
watch $0.30 SOLD
glasses $0.50 LISTED
glasses $0.50 LISTED
glasses $0.50 LISTED
glasses $1.00 SOLD
What I require is below output by a Group by SQL:
Item Name Total Fee Total Listed Total Sold
watch $0.70 2 1
glasses $2.50 3 1
The rule is that each "Item name" will having multiple records of listing, where fee and listing type is defined. There could be two "listing type" [LISTED & SOLD].
I want to run a query on the table and generate the summary like output mentioned.
thanks
wikki
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将使用静态“列表类型”总结列表。如果需要动态列表,则必须在存储过程中构建 SQL 并执行它。
输出:
您可以更进一步:
输出:
This will summarize the list using static "Listing Types". If you want a dynamic list, you would have to build the SQL in a stored procedure, and execute it.
Output:
You could take this a step further:
Output:
首先 - 您应该按项目对这些记录进行分组,然后要计算总数,您可以使用一个小技巧 -
Firstly - you should group these records by items, then to count totals you can use a small trick -