当前位置:首页 » 编程语言 » 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='王菲')