Ⅰ oracle 列轉行的問題。圖1是資料庫查詢的結果 圖二是我想要的結果的格式,謝謝了。
如果你的列是固定的,無論多少行,都可以通過典型的case when語句來處理,由於你圖1不太能看清,我們假設你想顯示列名為typeid,值為1,3,4的分列統計信息,則sql語句如下:
selectorgid,
sum((casewhentypeid=1then1else0end))astypeid1,
sum((casewhentypeid=3then1else0end))astypeid3,
sum((casewhentypeid=4then1else0end))astypeid4
fromTable001where1=1
groupbyorgid
如能提供清晰的圖1,我再寫給你完全可執行的SQL
Ⅱ DB2資料庫問題,列轉行問題
我給你一個思路如果假設你的rolename只有三個角色
我就不管你前面的結果是怎麼查出來的,你就以你前面結果為基本進行查詢
with a1 as (
select row_number() over(partition by name order by type) seq,
a.username,
a.loginid,
substr(a.orgcode,1,6) zq,
a.orgcode,
a.userstatus,
a.mobile,
c.rolename from s_u_user a
left join s_u_user_to_role b on a.id=b.userid
left join s_u_role c on b.roleid=c.id
where 1 = 1 and a.orgcode like '442028%' and a.id in (select userid from s_u_user_to_role where substr(roleid,1,9) like 'sbyw_role%')
select username,loginid,zq,orgcode,userstatus,mobile,
case (select count(*) from a1 b1 where b1.name=a1.name)
when 1 then (select rolename from a1 b1 where b1.name=a1.name)
when 2 then (select rolename from a1 b1
here b1.name=a1.name and seq =1)||','||
(select type from a1 b1
where b1.name=a1.name and seq =2)
ELSE '市局管理員,分局專員,社區業務員' END rolename
from a1 group by username,loginid,zq,orgcode,userstatus,mobile;
為了這個我也想了很長時間了,期待採納
Ⅲ 怎樣查詢SQL資料庫中某一個表中的某個列的一個數值的所有行數據
select * from accuont where VIP = 1
//上面的1 是在你表中的類型為數字類型的時候
select * from accuont where VIP='1'
//上面的1 是在你表中的類型為非數字類型的時候
第一個:查詢下拉框的選項
select a.Name,a.ID form TBMenu a where a.IsUsed=1
查詢Name和ID: Name為顯示文字,ID用於在選擇這個選項後根據ID值進行下一步的查詢
在你後台執行SQL的時候返回一個dateset 然後用combobox的datasuoce綁定,怎麼綁需要自己找例子,很好的學習過程。
第二個:根據選擇的菜單查詢需要的信息
select * from Infomations a where a.MenuID=ID(選擇下拉框選項對應的ID值)
在下拉框中選擇「主食」,點擊查詢按鈕,肯定是要查詢和主食相關的數據,那就通過主食對應的ID(也就是下拉框綁定的時候查詢的ID)去資料庫對應的關聯表中查詢對應的信息。
這個地方你沒有描述清楚你想實現的效果所以,根據你在上面補充的內容推測出的這些東西。
Ⅳ 怎麼查詢SQL資料庫中一行多列的數據中最大值
1、下載phpStudy,並且按照步驟安裝。
Ⅳ 如何在資料庫中得知最近一次數據
兩種方法
1、列轉行,將每月的數據轉成一行,即員工號、月份、數據這樣的格式,然後查詢。
2、使用case when逐月判斷。大概就是case when [09]<>'' then '09' when [08] <> '' then '08' when……else '' end
Ⅵ access資料庫中如何實現列轉行查詢
SELECT 姓名,'語文' AS 學科,語文 FROM 表
UNION
SELECT 姓名,'數學',數學 FROM 表
UNION
SELECT 姓名,'物理',物理 FROM 表
UNION
SELECT 姓名,'化學',化學 FROM 表
Ⅶ 在做操作資料庫中,我們怎麼查詢資料庫中的數據數據查詢方法是
SQL的核心是查詢。基本語法格式SELECT–FROM—WHERE查詢塊組成。因此,查詢命令也稱作SELECT命令。
數據查詢方法是:select 欄位名 from 表名 where 條件
Ⅷ SQL資料庫中怎麼從資料庫中通過一列中某行的某個數字查找到該行
查詢某行:
select
*
from
表名
where
ID=?這個ID為你表的ID,?為你要查詢的某列
查詢某列:select
列名
from
表名