sql查詢語句

2021-07-30 02:00:34 字數 1632 閱讀 3938

1.從表a中複製符合條件的記錄,修改部分字段,再存入a表

從表t_collect_line_point查詢欄位collectline_id=?1 並且欄位sort在?2和?3之間的所有記錄, 修改這些記錄的collectline_id欄位為48,把修改後的這些記錄再入該錶

insert

into t_collect_line_point (collectline_id,name,sort,altitude,latitude,longitude,pic_url,remark)

select

48,name,sort,altitude,latitude,longitude,pic_url,remark

from t_collect_line_point clp

where clp.collectline_id = ?1

and (clp.sort between ? and ?)

2.三張表路線表t_collect_line,目的地表t_destination_point,區域表t_area

其中路線表通過欄位destination_point_id關聯到目的地表

目的地表通過欄位area_id關聯到區域表

要求:查詢t_collect_line表中destination_point_id沒有關聯的記錄**或者**destination_point_id關聯了目的地表,但是被關聯的目的地記錄沒有關聯區域

sql查詢語句如下:

select line.* from t_collect_line as line

where line.destination_point_id is

null

orexists(select point.id from t_destination_point as point where point.id=line.destination_point_id and point.area_id is

null )

exists 運算子用於在滿足一定條件的指定表中搜尋行的存在

3子查詢

有三張表:

物資表material(id,名稱,編號)

倉庫表warehouse(id,名稱)

庫存表stock(id,倉庫id,物資id,庫存數量total)

查詢:查詢庫存表,並且根據倉庫id和物資id分組,查詢總共有多少組

方法1: 用子查詢,直接查詢出分組組數

select count(*) as total from (select count(*)

from wzgl_stock group

by warehouseid,materialid) as childsql

// $total=$totalarray[0]["total"]; 結果是個陣列

方法2:直接查詢出所有分組後的記錄,記錄條數就是分組的組數

select *  from wzgl_stock group

by warehouseid

//結果得到的集合的長度就是分組組數

sql 語句 查詢

例11 1 1 use xk gocreate trigger test1 on student for update as print 記錄已修改!go 2 update student set pwd 11111111 where stuno 00000001 例11 3 1 use xk go...

SQL查詢語句

create or replace procedure imms pk reportsend fromdate varchar2,todate varchar2 as function 系統效能統計 author qja 功能 將imms statusreport 表和imms report sen...

sql查詢語句

條件查詢 select 列名列表 from 表名 where 條件 where 條件 用來篩選滿足條件的記錄 行 條件有6種形式 1.比較大小 列名 比較運算子 值 查詢圖書 超過30元的圖書資訊 select from book where price 30 查詢清華大學出版社出版的圖書資訊 se...