SELECT * FROM `表名` WHERE 类型="乙" ORDER BY rand() limit 0,1;
我想要的就是 取4条记录出来,其中 类型=甲有3条 类型=乙有1条
如何用一条sql语句执行.
望高手给出结果,
6 个解决方案
#1
select top 3 * from tracy where AZWZ='1330采面'
union all
select top 1* from tracy where AZWZ='223水仓'
/*
AZWZ PJZ ZDZ BCSJ
1330采面 0.33 0.34 2010-01-01 00:00:00.000
1330采面 0.33 0.34 2010-01-01 00:05:00.000
1330采面 0.33 0.34 2010-01-01 00:00:00.000
223水仓 0.33 0.34 2010-01-01 00:00:00.000
*/
感觉不用union all一条语句实现有难度
#2
查询不出来阿..报错 #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3 * FROM `musicData` WHERE musicType="joke" union all SELECT TOP 1 * FROM `music' at line 1
#3
汗,Mysql的,你来错地方了。去对应的板块问问吧
#4
我这是mysql 不支持top阿
#5
那你能帮帮我解决下这个问题不
#6
(SELECT * FROM `表名` WHERE 类型="甲" ORDER BY rand() limit 0,3)
union all
(SELECT * FROM `表名` WHERE 类型="乙" ORDER BY rand() limit 0,1);
#1
select top 3 * from tracy where AZWZ='1330采面'
union all
select top 1* from tracy where AZWZ='223水仓'
/*
AZWZ PJZ ZDZ BCSJ
1330采面 0.33 0.34 2010-01-01 00:00:00.000
1330采面 0.33 0.34 2010-01-01 00:05:00.000
1330采面 0.33 0.34 2010-01-01 00:00:00.000
223水仓 0.33 0.34 2010-01-01 00:00:00.000
*/
感觉不用union all一条语句实现有难度
#2
查询不出来阿..报错 #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3 * FROM `musicData` WHERE musicType="joke" union all SELECT TOP 1 * FROM `music' at line 1
#3
汗,Mysql的,你来错地方了。去对应的板块问问吧
#4
我这是mysql 不支持top阿
#5
那你能帮帮我解决下这个问题不
#6
(SELECT * FROM `表名` WHERE 类型="甲" ORDER BY rand() limit 0,3)
union all
(SELECT * FROM `表名` WHERE 类型="乙" ORDER BY rand() limit 0,1);