當前位置:首頁 » 編程語言 » csqlselect語句
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

csqlselect語句

發布時間: 2022-07-18 11:54:42

sql Select 語句的用法

以下是代碼片段:
SQL:
select
*
into
b
from
a
where
1<>1說明:拷貝表(拷貝數據,源表名:a
目標表名:b)以下是代碼片段:
SQL:
insert
into
b(a,
b,
c)
select
d,e,f
from
b;說明:顯示文章、提交人和最後回復時間以下是代碼片段:
SQL:
select
a.title,a.username,b.adddate
from
table
a,(select
max(adddate)
adddate
from
table
where
table.title=a.title)
b說明:外連接查詢(表名1:a
表名2:b)以下是代碼片段:
SQL:
select
a.a,
a.b,
a.c,
b.c,
b.d,
b.f
from
a
LEFT
OUT
JOIN
b
ON
a.a
=
b.c說明:日程安排提前五分鍾提醒以下是代碼片段:
SQL:
select
*
from
日程安排
where
datediff(』minute』,f開始時間,getdate())>5
說明:兩張關聯表,刪除主表中已經在副表中沒有的信息
SQL:
以下是代碼片段:
delete
from
info
where
not
exists
(
select
*
from
infobz
where
info.infid=infobz.infid 說明:--
SQL:
以下是代碼片段:
SELECT
A.NUM,
A.NAME,
B.UPD_DATE,
B.PREV_UPD_DATE

FROM
TABLE1,

(SELECT
X.NUM,
X.UPD_DATE,
Y.UPD_DATE
PREV_UPD_DATE

FROM
(SELECT
NUM,
UPD_DATE,
INBOUND_QTY,
STOCK_ONHAND

FROM
TABLE2

WHERE
TO_CHAR(UPD_DATE,』YYYY/MM』)
=
TO_CHAR(SYSDATE,
』YYYY/MM』))
X,

(SELECT
NUM,
UPD_DATE,
STOCK_ONHAND

FROM
TABLE2

WHERE
TO_CHAR(UPD_DATE,』YYYY/MM』)
=

TO_CHAR(TO_DATE(TO_CHAR(SYSDATE,
』YYYY/MM』)
¦¦
』/01』,』YYYY/MM/DD』)
-
1,
』YYYY/MM』)
Y,

WHERE
X.NUM
=
Y.NUM
(+)

AND
X.INBOUND_QTY
+
NVL(Y.STOCK_ONHAND,0)
<>
X.STOCK_ONHAND
B
WHERE
A.NUM
=
B.NUM說明:--
SQL:
以下是代碼片段:
select
*
from
studentinfo
where
not
exists(select
*
from
student
where
studentinfo.id=student.id)
and
系名稱=』"&strdepartmentname&"』
and
專業名稱=』"&strprofessionname&"』
order
by
性別,生源地,高考總成績說明:
資料庫中去一年的各單位電話費統計(電話費定額賀電化肥清單兩個表來源)
SQL:
以下是代碼片段:
SELECT
a.userper,
a.tel,
a.standfee,
TO_CHAR(a.telfeedate,
』yyyy』)
AS
telyear,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』01』,
a.factration))
AS
JAN,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』02』,
a.factration))
AS
FRI,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』03』,
a.factration))
AS
MAR,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』04』,
a.factration))
AS
APR,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』05』,
a.factration))
AS
MAY,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』06』,
a.factration))
AS
JUE,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』07』,
a.factration))
AS
JUL,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』08』,
a.factration))
AS
AGU,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』09』,
a.factration))
AS
SEP,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』10』,
a.factration))
AS
OCT,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』11』,
a.factration))
AS
NOV,

SUM(decode(TO_CHAR(a.telfeedate,
』mm』),
』12』,
a.factration))
AS
DEC
FROM
(SELECT
a.userper,
a.tel,
a.standfee,
b.telfeedate,
b.factration

FROM
TELFEESTAND
a,
TELFEE
b

WHERE
a.tel
=
b.telfax)
a
GROUP
BY
a.userper,
a.tel,
a.standfee,
TO_CHAR(a.telfeedate,
』yyyy』)說明:四表聯查問題:SQL:
以下是代碼片段:
select
*
from
a
left
inner
join
b
on
a.a=b.b
right
inner
join
c
on
a.a=c.c
inner
join
d
on
a.a=d.d
where
.....說明:得到表中最小的未使用的ID號
SQL:
以下是代碼片段:
SELECT
(CASE
WHEN
EXISTS(SELECT
*
FROM
Handle
b
WHERE
b.HandleID
=
1)
THEN
MIN(HandleID)
+
1
ELSE
1
END)
as
HandleID
FROM
Handle
WHERE
NOT
HandleID
IN
(SELECT
a.HandleID
-
1
FROM
Handle
a)

❷ SQL語句 select操作

  • select 語句 基本格式如下

  • select [列名],[列名]...[或*] from [表名] where 查詢條件 group by 分組條件 order by 排序條件

  • 步驟閱讀

  • 5

    用法四,對查詢的結果按條件排序

    select SUBSTRING(city,1,1),count(1) from city group by SUBSTRING(city,1,1)

    order by COUNT(1) desc

    對上述分組結果,按數據排序,由大到小

❸ SQL 的一個SELECT語句解釋一下.

在這里的意思是給@userId
賦值
這時候如果
TableName
裡面有多個userid
就會得到最後1條

❹ sql的select語句

where stcd = 'hy_stsc_a.dbo.stcd'
上面這個條件,你確定么?
單引號之間的內容,這么寫就是字元串了。
也就是說stcd這個欄位里,有那個'hy_stsc_a.dbo.stcd' 串?
還有,你的p列,子查詢並沒有和外邊的表hy_stsc_a相連,這樣查詢即使不空,所有行的p欄位肯定也是一樣的。

❺ SQL的Select語句~

select 教師名
from 教師表
where 教師名 in(select 教師名 from 學生信息表 where 班級=N/*N表示所查詢的班級名稱*/ OR 年級=N/*同上*/)
我也不知道可以不,你試試看,服合你的要求嗎?

❻ 簡述SQL語言中SELECT語句的基本結構

Select 查詢語句
語法:SELECT [ALL|DISTINCT] <目標列表達式> [AS 列名]
[,<目標列表達式> [AS 列名] ...] FROM <表名> [,<表名>…]
[WHERE <條件表達式> [AND|OR <條件表達式>...]
[GROUP BY 列名 [HAVING <條件表達式>>
[ORDER BY 列名 [ASC | DESC>
解釋:[ALL|DISTINCT] ALL:全部; DISTINCT:不包括重復行
<目標列表達式> 對欄位可使用AVG、COUNT、SUM、MIN、MAX、運算符等
<條件表達式>
查詢條件 謂詞
比較 =、>,<,>=,<=,!=,<>,
確定范圍 BETWEEN AND、NOT BETWEEN AND
確定集合 IN、NOT IN
字元匹配 LIKE(「%」匹配任何長度,「_」匹配一個字元)、NOT LIKE
空值 IS NULL、IS NOT NULL
子查詢 ANY、ALL、EXISTS
集合查詢 UNION(並)、INTERSECT(交)、MINUS(差)
多重條件 AND、OR、NOT
<GROUP BY 列名> 對查詢結果分組
[HAVING <條件表達式>] 分組篩選條件
[ORDER BY 列名 [ASC | DESC> 對查詢結果排序;ASC:升序 DESC:降序
例1: select student.sno as 學號, student.name as 姓名, course as 課程名, score as 成績 from score,student where student.sid=score.sid and score.sid=:sid
例2:select student.sno as 學號, student.name as 姓名,AVG(score) as 平均分 from score,student where student.sid=score.sid and student.class=:class and (term=5 or term=6) group by student.sno, student.name having count(*)>0 order by 平均分 DESC
例3:select * from score where sid like '9634'
例4:select * from student where class in (select class from student where name='楊全')

❼ sql中的select 語句

SELECT Owner_id,COUNT(Owner_id) AS HYGS into #ls FROM BEFRIEND WHERE
Friend_id IN (select Friend_id from BEFRIEND where Owner_id='A') --與A共同好友關系的人
AND Friend_id!='A' --與A非好友關系
order by HYGS desc
select top 10 * from SITEUSER where Id in(select * from #ls)

❽ sql中select的作用是

作用就是從資料庫中檢索數據,並將查詢結果返回給用戶。

Select語句由select子句(查詢內容)、from子句(查詢對象)、where子旬(查詢條件)、order by子句(排序方式)、group by子句(分組方式)等組成。

計算列出在FROM中的所有元素。(FROM 中的每個元素都是一個真正的或者虛擬的表。)如果在 FROM 列表裡聲明了多過一個元素,那麼他們就交叉連接在一起。

如果聲明了WHERE子句,那麼在輸出中消除所有不滿足條件的行。如果聲明了GROUP BY子句,輸出就分成匹配一個或多個數值的不同組里。如果出現了HAVING子句,那麼它消除那些不滿足給出條件的組。



(8)csqlselect語句擴展閱讀:

DISTINCT從結果中刪除那些重復的行。DISTINCT ON 刪除那些匹配所有指定表達式的行。ALL (預設)將返回所有候選行,包括重復的。

如果給出了LIMIT或者OFFSET子句,那麼 SELECT 語句只返回結果行的一個子集。

如果聲明了 FOR UPDATE 或者 FOR SHARE 子句, SELECT 語句對並發的更新鎖住選定的行。

你必須有 SELECT 許可權用來從表中讀取數值。使用 FOR UPDATE FOR SHARE 還要求UPDATE許可權。

❾ SQL select語句

1.select
count
course
from
sc
group
by
course
2.select
avg
age
from
sc,s
where
sc
sno=s
sno
and
course='c4'
3.
select
avg
grade
from
sc
where
學分='3'
4.select
sname
from
s
where
sno>(select
sno
from
s
where
sname='王非')
and
sage
<(select
sage
from
s
where
sname='王非')
如果表名和欄位名對的話,就直接復制到查詢分析器里就成了

❿ SQL SELECT 語句

--學生表,欄位:ID,名字,年齡
declare
@student
table(
stu_id
int,
stu_name
varchar(16)
age
int
)
--課程表,欄位:ID,名字,學分
declare
@course
table(
cou_id
int,
cou_name
varchar(12)
cou_score
int
)
--學生選修課程表,欄位:學生ID,課程ID,分數
declare
@sc
table(
stu_id
int,
cou_id
int,
score
int
)
--插入數據
insert
@student
select
1,'劉德華',47
union
all
select
1,'張學友',46
(1)select
count(distinct
cou_name)
as
'選修課程門數'
from
@course
(2)select
avg(sum(age))
as
'選修C4課程的學生的平均年齡'
from
@student
where
stu_id
in
(select
distinct
stu_id
from
@sc
where
cou_id
in
(select
distinct
cou_id
from
@course
where
cou_name='c4'))
(3)select
avg(sum(score))
as
'學分為3的每門課程的學生平均成績'
from
@sc
where
cou_id
in
(select
distinct
cou_id
from
@course
where
cou_score=3)
(4)select
stu_name
as
'學號比王菲大,年齡比他小的學生姓名'
from
@student
where
stu_id>(select
distinct
stu_id
from
@studnet
where
stu_nme='王菲')
and
age<(select
distinct
age
from
@student
where
stu_name='王菲')