當前位置:首頁 » 編程語言 » 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