SQL查询从一个表中选择一个值,从另一个表中选择另一个表,并显示计数

时间:2016-10-13 12:59:34

标签: mysql rdbms

enter image description here

**enter image description here**

这是两个表,我被困在这两个表之间的查询中。 我需要列出卖家名称和他们销售的不同类型智能手机的数量。此外,结果应按电话类型数的后代顺序排序。 在一栏中我需要卖家名称而另一栏我需要卖家出售的电话总数。

像lisa mcdonals一样卖3种不同类型的手机。

3 个答案:

答案 0 :(得分:2)

试试这个:

select S.sellerName, P.productID from seller S join product P on S.SellerID=P.SellerID order by P.productID;

答案 1 :(得分:1)

如果您将表名调整为自己的名称,这将有效:

SELECT Seller.SellerName,
       Product.ProductID
FROM   Seller
       LEFT JOIN Product
              ON Product.SellerID = Seller.SellerID
ORDER  BY ProductID DESC

答案 2 :(得分:1)

您必须加入这两个表并按@model ConflictOfInterest.Models.ReportParamters @{ if (Model.SelectedTab != "0") { <table border="0" cellpadding="0" cellspacing="0"> @{ if (Model.SelectedTab == "1") { <tr> <td style="font-weight:bolder">@Html.Label("Year", "Year:")</td> <td>@Html.DropDownListFor(model => model.Year, Enumerable.Empty<SelectListItem>(), (DateTime.Today.Year - 1).ToString(), new { @style = "width:200px;" }) </td> <td style="font-weight:bolder">@Html.Label("ReportType", "Report Type:")</td> <td>@Html.DropDownListFor(model => model.ReportType, new SelectList(ViewBag.ReportType, "value", "Text"), new { @style = "width:200px;" })</td> <td style="font-weight:bolder"> @Html.Label("Person", "Person:") @Html.Label("Group", "Group:") </td> <td> @Html.DropDownListFor(model => model.Group, new SelectList(ViewBag.GroupList, "value", "Text"), new { @style = "width:200px;" }) @Html.DropDownListFor(model => model.Person, Enumerable.Empty<SelectListItem>(), "All", new { @style = "width:200px;" })<br /> @Html.TextBox("sPerson") <input type="button" id="bPerson" value="Search" /> </td> </tr> } /*else { <tr> <td colspan="6"></td> </tr> }*/ } <tr> <td style="font-weight:bolder">@Html.Label("Division", "Division:")</td> <td>@Html.DropDownListFor(model => model.Division, new SelectList(ViewBag.Division, "value", "Text"), new { @style = "width:200px;" })</td> <td style="font-weight:bolder">@Html.Label("Department", "Department:")</td> <td>@Html.DropDownListFor(model => model.Department, Enumerable.Empty<SelectListItem>(), "All", new { @style = "width:200px;" })</td> <td style="font-weight:bolder">@Html.Label("Section", "Section:")</td> <td>@Html.DropDownListFor(model => model.Section, Enumerable.Empty<SelectListItem>(), "All", new { @style = "width:200px;" })</td> </tr> <tr> <td colspan="6"></td> </tr> </table> } else { <table border="0" cellpadding="0" cellspacing="0"> <tr> <td>Show the detail captered by direct reports.</td> </tr> </table> } } 对结果进行分组,以便计算每个卖家销售的手机数量。

SellerName

请注意,这些可能不是您的表名,因为您没有提供它们。