当前位置:首页 » 编程语言 » sql同一张表查多次
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql同一张表查多次

发布时间: 2023-04-05 18:13:28

sql语句问题,如何在一个表内进行两次查询

假设表名是people:
select a.id as id, a.name as name, b.name as parent_name
from people as a,
people as b
where a.parent_id=b.id
还有这样建表是最常用的方式啦,没问题的

⑵ sql2000(多次)调用同一个表实现查询

select sizename,num from 表名 where shopname = '店铺1' group by sizename order by sizename
得到的是店铺1下面这一列的数据,店铺2,店铺3的列同理可得,
你就像你图那样做个excel表格,把上面查询得到的数据从第三列开始写到excel表格里就行了

⑶ sql中可以用select根据2个不同条件查询同一个表同一个字段2次吗

使用两个left join 就行了
select m.*,a.user_name as name1,b.user_name as name2 from message as m left join user as a on m.send_id=a.user_id left join user as b on m.get_id=b.user_id

⑷ mssql 同表多次查询用一条SQL语句怎么写

select a.*,b.match from (
select id,
(case
when (tag like '%条件一%' and tag like '%条件二%' and tag like '%条件三%') then 3
when (tag like '%条件一%' and tag like '%条件二%') then 2
when (tag like '%条件一%') then 1
else 0
end) as match
from [str]
) b join [str] a on a.id=b.id
where b.match>0
order by b.match desc