2

itemとsale_invoice_itemsの2 つのテーブルがあり、 itemsにはアイテムの有効期限が切れているかどうかを示すフラグがあり、sale_invoice_items には有効期限があります。今私がやっている請求書を返すために SELECT を実行するとき:

select  items.name as f1,  IF( items.expiry =TRUE,  sale_invoice_items.expiry, '-') as f2    
from sale_invoices, sale_invoice_items, items where  sale_invoices.id = 3 and sale_invoice_items.invoice_id = sale_invoices.id and items.id = sale_invoice_items.item_id

そのため、アイテムの有効期限が切れている場合は、フィールドに有効期限を返します。それ以外の場合は、「-」と書きます

アイテム名は問題なく返されますが、有効期限は返されず、代わりにバイト配列が返されます。

私は何を間違っていますか?

4

1 に答える 1

2
select
....
, case when items.expiry = true then 
     sales_invoice_items.expiry 
else 
     '-' 
end as expiry
....
from
....

のデータ型を確認する必要があります。

sales_invoice_items.expiry

'-'

同じつまり文字です。ここで変換関数を使用できます

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format

これを達成するために。

日付を返したい場合は、「その他」の場合に期待する値を決定する必要があります: ダミーの日付、null....?

于 2013-05-25T12:08:10.363 に答える