mysql查詢字段轉型 mysql轉型

2021-10-18 12:55:02 字數 942 閱讀 4997

1、將int 轉為varchar經常用 concat函式,比如concat(8,』0′) 得到字串 』80′

2、將varchar 轉為int 用 cast(a as signed) a為varchar型別的字串

總結:型別轉換和sql server一樣,就是型別引數有點點不同 : cast(*** as 型別) , convert(***,型別)

可用的型別

二進位制,同帶binary字首的效果 : binary

字元型,可帶引數 : char()

日期 : date

日期時間型 : datetime

浮點數 : decimal

整數 : signed

無符號整數 : unsigned

cast函式執行示例

mysql> select cast(』125e342.83′ as signed) as clm1, cast(『foo seo 589′ as signed) as clm2,cast(』3.35′ as signed) as clm3;

| clm1 | clm2 | clm3 |

|  125 |    0 |    3 |

1 row in set, 3 warnings (0.00 sec)

mysql>

cast(expr as type), convert(expr,type) , convert(expr using transcoding_name)

cast() 和convert() 函式可用來獲取乙個型別的值,並產生另乙個型別的值。

這個型別 可以是以下值其中的 乙個:

binary[(n)]

char[(n)]

date

datetime

decimal

signed [integer]

time

unsigned [integer]

mysql 查詢字段排名 mysql 查詢排名

sql語句查詢排名 思路 有點類似迴圈裡面的自增一樣,設定乙個變數並賦予初始值,迴圈一次自增加1,從而實現排序 mysql裡則是需要先將資料查詢出來並先行按照需要排序的字段做好降序desc,或則公升序asc,設定好排序的變數 初始值為0 a 將已經排序好的資料從第一條依次取出來,取一條就自增加一,實...

mysql查詢字段排序 mysql 排序查詢字段

mysql 排序查詢字段 閱讀 504 排序查詢 語法 select 查詢欄位1 from 表 where 篩選條件 order by 要排序欄位2 asc公升序 desc 降序,要排字段3 asc公升序 desc降序 如果不寫預設為公升序 案例 查詢員工資訊,要求工資從高到低排序 select f...

mysql統計查詢並查詢字段

select count 1 ifvote d.voteitemid from tp votedetail d where d.fgsid and d.voteid 943306615853940736 and d.personid 011217033621526565 order by d.vot...