SQL语句中查询的用法

2025-12-04 23:47:47
推荐回答(3个)
回答1:

distinct的作用就是去除重复的列。比如
一张表student(姓名,年级)然后里面有许多数据,例如:
姓名
年级
张三
大一
张三
大二
李四
大三
王五
大一
让你查询出
student表中,有几种姓名?
如果你写成:
select
姓名
from
student
那么结果是:
姓名
张三
张三
李四
王五
这样的话,就会出现两个张三
这样既占用空间,又不符合常理,这时候
如果你用distinct关键字的话,则:
select
distinct
姓名
from
student
结果是:
姓名
张三
李四
王五
总之,一句话,distinct就是去除重复列的。
明白了把?看在我写那么多的费上,给我分吧~~(*^__^*)

回答2:

@是用于预处理语句的,有点类似与变量命名。
下面是个例子。
prepare
cdo6
from
"select
count(id)
from
test_table_a,
test_table_b
where
site
like
?
and
img=id
"
set
@domain:='%test.com%'
execute
cdo6
using
@domain

回答3:

select
distinct(2)
from

这样查询出的是第二列不重复的内容!