简体   繁体   English

mysql,根据类别的UUID获取产品的总重量

[英]mysql, get total weight of products from based on UUID of category

I am attempting to aquire the total weight of gear, and the name of the category, based on the category that the gear is listed within. 我正在尝试根据齿轮在其中列出的类别来获取齿轮的总重量以及类别的名称。

I have three tables of concern. 我有三个关注的表。

'gear' (which holds the information about each piece of gear, including the weight) and it has a UUID and the weight field is called "Weight" “齿轮”(包含有关每个齿轮的信息,包括重量),并具有UUID,重量字段称为“重量”

'gear_list' (which holds the name of the category in a field called "Subject" and has its own UUID) 'gear_list'(在名为“ Subject”的字段中保存类别的名称,并具有自己的UUID)

'gear_list_items' (which contains the GearUUID, GearListUUID, CategoryUUID) 'gear_list_items'(包含GearUUID,GearListUUID,CategoryUUID)

What I am able to pass to the php script is the GearListUUID. 我能够传递给php脚本的是GearListUUID。

So what I am needing here is a way to query and have results such as this: 因此,我在这里需要的是一种查询并产生如下结果的方法:

CategoryName, 268 (weight/grams) AnotherCategoryName, 485 (weight/grams) AnotherCategoryName, 1028 (weight/grams) AnotherCategoryName, 768 (weight/grams) AnotherCategoryName, 448 (weight/grams) CategoryName,268(重量/克)AnotherCategoryName,485(重量/克)AnotherCategoryName,1028(重量/克)AnotherCategoryName,768(重量/克)AnotherCategoryName,448(重量/克)

I suspect I may need to post some schema dump, but if anybody has knowledge of how to do this before I go and post all that, it would be highly appreciated. 我怀疑我可能需要发布一些模式转储,但是如果有人在我发布所有内容之前都知道如何进行此操作,将不胜感激。

It's hard to tell for sure without seeing actual table schemas and sample data but you want something like 在没有看到实际的表模式和示例数据的情况下很难确定,但是您想要类似

SELECT l.Subject, SUM(g.Weight) Weight
  FROM gear_list l JOIN gear_list_items i
    ON l.GearListUUID = i.GearListUUID JOIN gear g
    ON i.GearUUID = g.GearUUID
-- WHERE l. GearListUUID = ?
 GROUP BY l.Subject

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM