這種一般是sql語句的錯誤。你將php變數改為值之後將sql語句放到phpmyadmin或其他mysql工具里試一下是否能查到
❷ 請教資料庫腳本語言的嵌套查詢幾個問題
--汗,,,我不就是錄入數據的時候用001表示你的1001嘛,,現在我改過來了。你在試試看。
--我偷懶,你不能偷懶啊。
--以下在SQL2005測試通過。
create table #stu_cour(cno varchar(10),sno varchar(10),grade int)
create table #student(sno varchar(10),sname varchar(10),deptno varchar(10))
create table #teacher(tno varchar(10),tname varchar(10),deptno varchar(10))
create table #course(cno varchar(10),cname varchar(10), tno varchar(10), credit int)
insert #stu_cour
select 'sx','1001',100 union all
select 'yw','1001',76 union all
select 'yy','1001',54 union all
select 'sx','1002',85 union all
select 'yy','1002',60 union all
select 'hx','1002',66 union all
select 'sx','1003',77 union all
select 'yy','1003',88 union all
select 'sx','1004',99 union all
select 'yw','1004',98 union all
select 'yy','1004',67 union all
select 'sx','1005',89 union all
select 'yy','1005',78 union all
select 'yw','1005',56
insert #student
select '1001','學生1','081班' union all
select '1002','學生2','081班' union all
select '1003','學生3','081班' union all
select '1004','學生4','082班' union all
select '1005','學生5','082班'
insert #teacher
select 'T1','張星','081班' union all
select 'T2','老師2','082班'
insert #course
select 'sx','數學','T1',null union all
select 'yw','語文','T1',null union all
select 'hx','化學','T2',null union all
select 'yy','英語','T2',null
--1.各門功課取得最高成績的學生姓名及其成績
select c.cname,s.sname,max(sc.grade) maxgrade
from #student s join #stu_cour sc on s.sno=sc.sno
join #course c on sc.cno=c.cno
group by c.cname,sc.cno,s.sname
having max(sc.grade) >=all(
select max(sc2.grade)
from #stu_cour sc2 where sc.cno=sc2.cno
group by sc2.cno
)
--2.查詢選修了1001學生選修的全部課程的學生學號(即:學生2、學生3)
select distinct sno
from #stu_cour sc
where not exists
(
select cno
from #stu_cour
where sno='1001'
and
cno not in (select cno from #stu_cour where sno=sc.sno)
)
--3.查詢選修了tname=『張星』開設的全部課程的學生姓名(即:學生2、學生3)
select distinct s.sname
from #stu_cour sc join #student s on sc.sno=s.sno
where not exists
(
select cno
from #teacher t join #course c on t.tno=c.tno
where tname='張星'
and
cno not in (select cno from #stu_cour where sno=sc.sno)
)
drop table #stu_cour
drop table #student
drop table #teacher
drop table #course
❸ sql 腳本 查詢語句(sqlserver資料庫)
select
case when id=1 then values end as 'A',
case when id=2 then values end as 'B',
case when id=3 then values end as 'C',
case when id=4 then values end as 'D',
max(create_time)
from 表 where create_time=(select max(create_time) from 表 )
group by
case when id=1 then values end ,
case when id=2 then values end ,
case when id=3 then values end ,
case when id=4 then values end
❹ 如何使用SQL腳本查看資料庫中表的擴展屬性
很多客戶不知道如何使用sql
server資料庫的查詢分析器來執行sql語句命令或者sql腳本,這里我們以sql2005資料庫為例,來講解如何使用sql資料庫查詢分析器
1、首先連接您的資料庫,
2、連接成功後
3、sql2005資料庫:選擇您的資料庫然後點擊「新建查詢」
sql2000資料庫:選擇您的資料庫然後選擇工具---sql查詢分析器
4、打開查詢分析器後,輸入sql執行語句或者打開sql腳本文件執行:
5、sql執行語句輸入後,選擇「執行」按鈕(!感嘆號)或者按f5來執行命令
註:在使用查詢分析器執行sql語句之前,建議您先對您的資料庫進行備份。
❺ js腳本中能進行資料庫的查詢么
js是運行在客戶端的,不能查詢遠程資料庫。
就算ajax也好,jquery也好 ,ext js也好,在沒有伺服器端程序(java、php等)的支持下都是無法查詢資料庫的。
❻ 如何查看mysql資料庫中的腳本文件
sql腳本是包含一到多個sql命令的sql語句,我們可以將這些sql腳本放在一個文本文件中(我們稱之為「sql腳本文件」),然後通過相關的命令執行這個sql腳本文件。基本步驟如下:
1、創建包含sql命令的sql腳本文件
文件中包含一些列的sql語句,每條語句最後以;結尾,文件內容示例如下:
--創建表,使用「--」進行注釋
create table 表名稱
(
Guid Varchar(38) not null primary key,
Title Varchar(255),
) TYPE=InnoDB;
--在表A中增加欄位Status
alter table A add Status TinyInt default '0';
--在表A上創建索引
create index XX_TaskId_1 on A(Id_);
--在表A中添加一條記錄
Insert into A (Id,ParentId, Name) values(1,0,'名稱');
--添加、修改、刪除數據後,有可能需要提交事務
Commit;
2、執行sql腳本文件
方法一 使用cmd命令執行(windows下,unix或linux在的其控制台下)
【Mysql的bin目錄】\mysql –u用戶名 –p密碼 –D資料庫<【sql腳本文件路徑全名】,示例:
D:\mysql\bin\mysql –uroot –p123456 -Dtest
注意:
A、如果在sql腳本文件中使用了use 資料庫,則-D資料庫選項可以忽略
B、如果【Mysql的bin目錄】中包含空格,則需要使用「」包含,如:「C:\Program Files\mysql\bin\mysql」 –u用戶名 –p密碼 –D資料庫<【sql腳本文件路徑全名】
方法二 進入mysql的控制台後,使用source命令執行
Mysql>source 【sql腳本文件的路徑全名】
❼ oracle 資料庫查詢腳本 plsql
創建表
createtablea
(姓名varchar2(10),
狀態int,
更新時間date,
內容varchar2(20));
insertintoavalues('張三',1,to_date('2015-01-02','yyyy-mm-dd'),'測試數據1');
insertintoavalues('李四',1,to_date('2015-01-02','yyyy-mm-dd'),'測試數據2');
insertintoavalues('王五',1,to_date('2015-01-03','yyyy-mm-dd'),'測試數據3');
insertintoavalues('測試',0,to_date('2015-01-03','yyyy-mm-dd'),'測試數據4');
insertintoavalues('臨時',0,to_date('2015-01-03','yyyy-mm-dd'),'測試數據5');
insertintoavalues('管理員',1,to_date('2015-01-04','yyyy-mm-dd'),'測試數據6');
insertintoavalues('錄入員',1,to_date('2015-01-04','yyyy-mm-dd'),'測試數據7');
insertintoavalues('審核',1,to_date('2015-01-06','yyyy-mm-dd'),'測試數據8');
insertintoavalues('發布',0,to_date('2015-01-06','yyyy-mm-dd'),'測試數據9');
createtableb
(姓名varchar2(10),
性別varchar2(2),
工號varchar2(4),
備注varchar2(10));
insertintobvalues('張三','男','0001',null);
insertintobvalues('李四','男','0002',null);
insertintobvalues('王五','男','0003',null);
insertintobvalues('測試','男','0004',null);
insertintobvalues('臨時','男','0005',null);
insertintobvalues('管理員','男','0006',null);
insertintobvalues('錄入員','女','0007',null);
insertintobvalues('審核','女','0008',null);
insertintobvalues('發布','女','0009',null);
insertintobvalues('數據製作','女','0010',null);
insertintobvalues('美工','女','0011',null);
查詢:
selectb.姓名,
b.性別,
b.工號,
casewhena.狀態=1then1elsenullend狀態,
casewhena.狀態=1thena.更新時間elsenullend更新時間,
casewhena.狀態=1thena.內容elsenullend內容
froma,bwherea.姓名(+)=b.姓名;
查詢結果:
❽ 怎樣查看mysql資料庫的腳本
obj.style.display="none";
}
}
function closeBox(){
slideAd(id,this.stayTime,"up",nMaxHth,nMinHth);
}
intervalId = window.setInterval(openBox,10);
}
</script>
</head>
</head>
<body>
❾ 資料庫查詢腳本
你查詢序列號最大的,02不就是 你a1中最大的么? 沒寫錯。
是你要返回的結果弄錯了。
返回結果應該是:
02 a1 2 a01
05 b1 3 b01
❿ php網頁中調用php腳本查詢資料庫結果輸出到當前頁面
你要輸出什麼?我就假設兩個條件是數字,選好條件提交後,顯示條件1>還是<條件2吧。
<formaction=""method="post">
<label>條件1:
<selectname="select1">
<optionvalue="0"selected="selected">選項1</option>
<optionvalue="1">選項2</option>
</select>
</label>
<label>條件2:
<selectname="select2">
<optionvalue="0"selected="selected">選項1</option>
<optionvalue="1">選項2option>
<optionvalue="2">選項3</option>
</select>
</label>
<inputname="b1"type="submit"value="查詢"/>
<?php
if($_POST['select1']<$_POST['select2']){
echo$_POST['select1']."<".$_POST['select2'];
}elseif($_POST['select1']>$_POST['select2']){
echo$_POST['select1'].">".$_POST['select2'];
}
elseif($_POST['select1']=$_POST['select2']){
echo$_POST['select1']."=".$_POST['select2'];
}
?>