SQL其中Date大于X.

时间:2015-04-01 13:18:33

标签: mysql sql report

我正在尝试运行查询;

SELECT PO_PurchaseOrderDetail.ItemCodeDesc,   
       PO_PurchaseOrderDetail.QuantityOrdered, 
       PO_PurchaseOrderDetail.QuantityReceived, 
        PO_PurchaseOrderDetail.UnitCost, 
       PO_PurchaseOrderDetail.JT158_WTSalesOrderNo, 
       PO_PurchaseOrderDetail.PurchaseOrderNo, 
       PO_PurchaseOrderHeader.PurchaseName, 
       PO_PurchaseOrderHeader.PurchaseOrderDate
FROM PO_PurchaseOrderDetail PO_PurchaseOrderDetail, PO_PurchaseOrderHeader PO_PurchaseOrderHeader
WHERE (PO_PurchaseOrderDetail.PurchaseOrderNo=PO_PurchaseOrderHeader.PurchaseOrderNo) 
AND ***(PO_PurchaseOrderHeader.PurchaseOrderDate > '2013-12-31')***
ORDER BY PO_PurchaseOrderDetail.JT158_WTSalesOrderNo, PO_PurchaseOrderDetail.PurchaseOrderNo

我的问题是,日期以YYYY-MM-DD格式存储。我只需要在特定日期之后显示数据。因此,因为2013-12-31是字符串而不是数字,运算符>不起作用。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在以下内容中尝试CAST字符串为DATE

P.S。如果PurchaseOrderDate不是DATE数据类型,您也可以CAST It:CAST(PO_PurchaseOrderHeader.PurchaseOrderDate AS DATE)

SELECT PO_PurchaseOrderDetail.ItemCodeDesc,
       PO_PurchaseOrderDetail.QuantityOrdered,
       PO_PurchaseOrderDetail.QuantityReceived, 
       PO_PurchaseOrderDetail.UnitCost, 
       PO_PurchaseOrderDetail.JT158_WTSalesOrderNo, 
       PO_PurchaseOrderDetail.PurchaseOrderNo, 
       PO_PurchaseOrderHeader.PurchaseName, 
       PO_PurchaseOrderHeader.PurchaseOrderDate
FROM   PO_PurchaseOrderDetail PO_PurchaseOrderDetail, 
       PO_PurchaseOrderHeader PO_PurchaseOrderHeader
WHERE  PO_PurchaseOrderDetail.PurchaseOrderNo = PO_PurchaseOrderHeader.PurchaseOrderNo AND    
       PO_PurchaseOrderHeader.PurchaseOrderDate > CAST('2013-12-31' AS DATE)
ORDER BY PO_PurchaseOrderDetail.JT158_WTSalesOrderNo, 
         PO_PurchaseOrderDetail.PurchaseOrderNo