Select 来自 table 的随机行
Select random rows from table
我想从 Admin_Pic_Lib 的整个 table 中 select 随机 24 行,但是
此查询给出语法错误,
SELECT top 24 CAST( [Pictures] AS varbinary(Max)) FROM Admin_Pic_Lib ORDER BY NEWID()
UNION ALL
SELECT CAST([Pictures] AS varbinary(Max)) FROM User_images WHERE UserName ='ahmed'
当我修剪时 ORDER BY NEWID()
它只 select 前 24 行。
请尝试以下代码。
SELECT Pictures
FROM
(SELECT TOP 24 CAST([Pictures] AS varbinary(Max)) AS Pictures
FROM Admin_Pic_Lib ORDER BY NEWID()) AS X
UNION ALL
SELECT CAST([Pictures] AS varbinary(Max)) AS Pictures
FROM User_images
WHERE UserName ='ahmed'
我想从 Admin_Pic_Lib 的整个 table 中 select 随机 24 行,但是 此查询给出语法错误,
SELECT top 24 CAST( [Pictures] AS varbinary(Max)) FROM Admin_Pic_Lib ORDER BY NEWID()
UNION ALL
SELECT CAST([Pictures] AS varbinary(Max)) FROM User_images WHERE UserName ='ahmed'
当我修剪时 ORDER BY NEWID()
它只 select 前 24 行。
请尝试以下代码。
SELECT Pictures
FROM
(SELECT TOP 24 CAST([Pictures] AS varbinary(Max)) AS Pictures
FROM Admin_Pic_Lib ORDER BY NEWID()) AS X
UNION ALL
SELECT CAST([Pictures] AS varbinary(Max)) AS Pictures
FROM User_images
WHERE UserName ='ahmed'