1DECLARE @T TABLE([id]INT,[names] NVARCHAR(10),[sub] NVARCHAR(10))
INSERT @T SELECT 1,N'张三',N'语文'
INSERT @T SELECT 2,N'张三',N'英语'
INSERT @T SELECT 3,N'张三',N'数学'
INSERT @T SELECT 4,N'李四',N'数学'
INSERT @T SELECT 5,N'王五',N'英语'
INSERT @T SELECT 6,N'王五',N'数学'
SELECT NAMES from @t where names in(select names from @t group by names having count(names)=3)group by names
NAMES
----------
张三
2CREATE PROC MY_PROC
@kc NVARCHAR(50),
@sl INT output
AS
DECLARE @T TABLE([id]INT,[names] NVARCHAR(10),[sub] NVARCHAR(10))
INSERT @T SELECT 1,N'张三',N'语文'
INSERT @T SELECT 2,N'张三',N'英语'
INSERT @T SELECT 3,N'张三',N'数学'
INSERT @T SELECT 4,N'李四',N'数学'
INSERT @T SELECT 5,N'王五',N'英语'
INSERT @T SELECT 6,N'王五',N'数学'
SELECT @sl=count(names) FROM @t where @kc=sub
set nocount on
declare @n int
EXEC my_proc 数学,@n output
print(@n)
3CREATE TRIGGER MY_TRIGGER ON TABLE FOR INSERT
AS
DECLARE @Student NVARCHAR(20)
SELECT @Student=names from inserted
BEGIN TRAN
INSERT t_1 select from inserted
IF(@@ROWCOUNT<>0)
BEGIN
UPDATE TABLE SET Field=Field+1 where names=@Student
COMMIT TRAN
END
ELSE
ROLLBACK TRAN
4GRANT SELECT ON TABLE TO USERS--查询权限
GRANT UPDATE ON TABLE TO USERS--修改权限
5EXEC sp_addrole 'Student’ --创建角色
GRANT SELECT ON TABLE TO Student --授权角色查询
呵呵 希望对你有帮助,哪里不懂 Q我吧 275733728 触发器那题只是给你实例了一下,如果需求不对你可以按照你的需求再更改~
selectfromphome_ecms_memberprowhereuseridin(selectuseridfromphome_ecmswherechecked
--存储过程效率更高些这个写的不好。一般都不in查询因为他的效率特别低。而且不需要全部字段的话,尽量就不用select来查询。慢慢努力哦!
不可以哦,这不是MYSQL的问题,数据库都有这个规定:不允许UPDATE的子查询里面有被UPDATE的那个表。
我一般采取两种方法,一是利用SQL文本:
SELECT CONCAT("UPDATE RES_OBJECT SET MULTISELECT_ID=",
BMULTISELECT_ID,"WHERE RES_ID=",ARES_ID,";")
INTO OUTFILE ABCSQL
FROM RES_OBJECT A,RES_OBJECT B
WHERE BRES_ID=APARENT_NODE_RES_ID)
AND (RES_OBJECTMULTISELECT_ID IS NULL OR RES_OBJECTMULTISELECT_ID=0);
SOURCE ABCSQL;
另外一种方法是利用临时表:
SELECT BMULTISELECT_ID,ARES_ID
FROM RES_OBJECT A,RES_OBJECT B
WHERE BRES_ID=APARENT_NODE_RES_ID)
AND (RES_OBJECTMULTISELECT_ID IS NULL OR RES_OBJECTMULTISELECT_ID=0)
INTO TEMP TABLE TMP;
UPDATE RES_OBJECT SET MULTISELECT_ID=
(SELECT MULTISELECT_ID FROM TMP WHERE TMPRES_ID=RES_OBJECTRES_ID)
WHERE EXISTS
(SELECT MULTISELECT_ID FROM TMP WHERE TMPRES_ID=RES_OBJECTRES_ID);
"select from [Tab_Data] " & " where 时间 between #" & T1begin & "# and #" & T1End & "# " & " And 站号='" & Combo1Text & "' "
引号内的引号用单引号
xxxx & " And 站号='" & Combo1Text & "'"
否则在VB的语法中就出错了.你是用ACCESS数据库的吧?
以上就是关于MSSQL 嵌套查询 高手救命呀全部的内容,包括:MSSQL 嵌套查询 高手救命呀、sql多表多条件嵌套查询(mysql中多表嵌套查询例子)、mysql 如何对一张表进行嵌套查询等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)