2015-01-12 37 views
-2

我有下面的查詢哪些工作正常,但不知道在postgresql中的含義和使用::任何人都可以解釋::在postgresql意義?

select (
    select ( 
     case when 1 > 0 then 1::float/(
      select count(id) from transactions_products where transaction_id in (
      select id from transactions_transactions tt 
      where status = 3 and fi = 355 
       and (invoice_date >= 1420754400) 
       and (invoice_date <= 1421099999) 
       and (tt.division_id = 107) 
       and (tt.department_id = 210) 
     ) and is_vehicle = 1 
    )::float else 0 end) 
limit 1) as f_4 
+0

爲什麼在這裏標記sqlite,當它顯然是一個Mysql相關的問題? – jarlh

+0

這裏有幾個[相關問題](http://stackoverflow.com/questions/5758499/double-colon-notation-in-sql),但它們似乎與PostgreSQL有關。 – halfer

+4

當1不大於0? – Strawberry

回答

6

::是PostgreSQL的cast運算符。

+0

在mysql中不可能嗎? – Sandeep

+0

是的 - 使用['cast()'](http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html) –

+2

CAST()也是標準的SQL,可在許多數據庫中使用它支持某種形式的SQL。 –

0

簡而言之,不麻煩的答案:它將值轉換爲浮點值。

+0

你可能想詳細說明你的答案。只是說它會投入價值並不是很有用。爲什麼你想要投入價值?有更好的用例嗎? – Machavity

+0

我明白你的意思了,但是這個帖子只會變成對類型轉換的目的,優點和缺點的一般性討論。 – Dencker

+1

你不需要深入細節,只需解釋爲什麼你會使用一個或爲OP提供一些東西繼續下去。你假設每個人都知道鑄造是什麼。請注意,最常見的答案有更多信息的鏈接。 – Machavity

相關問題