我如何获得最小值 [英] how to do i get the min values
问题描述
SELECT o.ORD_CUS_ID,
min(ODD_RequestDate)为 ODD_RequestDate
FROM
订单 JOIN 订单详细信息 as c
打开
c.ODD_ORD_ID = o.ORD_ID
组 BY o.ORD_CUS_ID
我已经使用上面的代码来获取请求日期的最小值.
请求日期属性在orderdetails表中.
我已经存储了一个名为usp_orders的过程,该过程同时具有orders表和orderdetails表,在其中必须保持上述关系以获取请求日期的最小值.
但是我执行上面的代码时,IAM收到以下错误
消息 208 ,级别 16 ,状态 1 行
无效的对象名称' OrdersPhi'.
sridevikavalakuntla写道:无效的对象名称"OrdersPhi"
您所提供的查询中没有所谓的"OrderPhi".
检查您的存储过程是否正确键入.
sridevikavalakuntla写道:我必须给监护人输入输入(手动),这样我就应该得到与该客户需求和最小请求日期有关的订单.
因此,将其作为参数传递给存储过程.
创建 过程 [dbo].[test_GetOrders] @ CUST_ID int AS ........ ........ 位置 o.ORD_CUS_ID = @ CUST_ID
我建议您购买一本好的SQL书或在网上阅读文章,因为如果您正在编写SQL查询,这是您应该知道的最基本的知识.
sridevikavalakuntla写道:可以获取,但是在输出时,当我输入cust_id/name作为输入时,我应该只获取价格和请求日期.但是我要获取表中所有的列名
那是因为您要选择查询中的所有列.
sridevikavalakuntla写道:(选择ORD_ID,ORD_NO,ORD_CUS_ID,CUS_Name,CUS_ECCNumber,CUS_TINCSTNumber,CUS_OfficeAddress,CUS_FactoryAddress,ORD_Advisedsy,ORD_STAT_ty, ,ORD_CUS_PONo,ORD_CreatedBy,dbo.fn_GetDatePart(ORD_CreatedDate)AS``ORD_CreatedDate'',ORD_LastModifiedBy,ORD_LastModifiedDate,isull(ORD_Date,ORD_CreatedDate)AS``ORD_Date''块/>
仅选择所需的列名称.
SELECT o.ORD_CUS_ID, min(ODD_RequestDate) as ODD_RequestDate FROM Orders o JOIN Orderdetails as c ON c.ODD_ORD_ID = o.ORD_ID GROUP BY o.ORD_CUS_ID
i have used the above code to get the min values of request date.
the request date attribute is in orderdetails table.
i have stored procedure by name usp_orders, which have both orders table and orderdetails table,in which i have to keep the above relation to get the min value for request date.
but iam getting the following error when i execute the above code
Msg 208, Level 16, State 1, Line 1 Invalid object name 'OrdersPhi'.解决方案sridevikavalakuntla wrote:Invalid object name ''OrdersPhi''
There is nothing called ''OrderPhi'' in the query you have given.
Check your stored procedure if it is typed correctly.
sridevikavalakuntla wrote:i have to give custid as input(manually) so i should get the oreders related to that custid and the min request date.
So pass it as a parameter to the stored procedure.
CREATE PROCEDURE [dbo].[test_GetOrders] @CUST_ID int AS ........ ........ WHERE o.ORD_CUS_ID = @CUST_ID
I would suggest you to buy a good SQL book or read articles on the web because it''s the most basic thing that you should know if you are writing an SQL Query.
sridevikavalakuntla wrote:iam getting it but while coming to the output i should get only the oders and request date when i give the cust_id/name as input. but iam getting all the column names that are in the table
That''s because you are selecting all columns in your query.
sridevikavalakuntla wrote:(SELECT ORD_ID, ORD_NO, ORD_CUS_ID, CUS_Name, CUS_ECCNumber, CUS_TINCSTNumber, CUS_OfficeAddress, CUS_FactoryAddress, ORD_AdvisedBy, ORD_DAN_No, ORD_Qty, ORD_Status, ORD_IsDelta, ORD_CUS_PONo, ORD_CreatedBy, dbo.fn_GetDatePart(ORD_CreatedDate) AS ''ORD_CreatedDate'', ORD_LastModifiedBy, ORD_LastModifiedDate, isnull(ORD_Date,ORD_CreatedDate) AS ''ORD_Date''
Select only the column names you want.
这篇关于我如何获得最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!