測試常用sql總結

  1. sql中查找爲空的記錄,使用IS NULL和IS NOT NULL關鍵字
select * from database.table where row1 IS NULL
select * from database.table where row1 IS NOT NULL
  1. 獲取數據表的列名等信息,也可以直接使用select * from information_schema.'COLUMNS’查看information.schema.'COLUMNS’表中都有什麼列名稱
select column_name from information_schema.'COLUMNS' where table_name = 'sql_table_name' and table_schema = 'db_name'
  1. 從數據庫中隨機取幾個值,如下例子所示爲從t_securities表中隨機取三個security_id
select security_id from t_securities order by rand() limit 3
  1. 獲取表中該列最大的值
select max(value_version) from t_config_item
  1. 根據數據表中的值作字典轉換,如數據庫中保存’101’實際意義爲上交所,'102’實際意義爲深交所
select security_id,if(market_id='101','上海','深圳') from t_securities
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章