SELECT
a.col1, b.col1, b.col2
FROM ta a
CROSS APPLY (
SELECT
tb.col1, tb.col2
FROM tb
WHERE tb.col3 = a.col1
)b
GROUP BY a.col1;
这样的语句,mysql怎么实现??
10 个解决方案
#1
mysql是不支持cross apply语法的
SELECT
a.col1, b.col1, b.col2
FROM ta a,tb b
WHERE b.col3 = a.col1
GROUP BY a.col1;
SELECT
a.col1, b.col1, b.col2
FROM ta a,tb b
WHERE b.col3 = a.col1
GROUP BY a.col1;
#2
MYSQL 没有CROSS APPLY,你要达到什么目的,
贴建表及插入记录的SQL,及要求结果出来看看
贴建表及插入记录的SQL,及要求结果出来看看
#3
表结构如下:
A是统计表,字段如下:
UserID,DepartA(部门), TJA,TJB
B是流水表
SEQ(自增), UserID, Act1,Act2
现在结果要求:从A和B表中加载所属部门为‘YX’ 所有人员的最后两条行为信息。
A是统计表,字段如下:
UserID,DepartA(部门), TJA,TJB
B是流水表
SEQ(自增), UserID, Act1,Act2
现在结果要求:从A和B表中加载所属部门为‘YX’ 所有人员的最后两条行为信息。
#4
select b.UserID, b.Act1, b.Act2 from b left join a on a.UserID = b.UserID where a.DepartA = 'YX' order by b.SEQ desc limit 2;
我刚学不久,不知道对不!
我刚学不久,不知道对不!
#5
楼上不对,坐等牛逼写法。
#6
贴建表及插入记录的SQL,及要求结果出来看看
#7
select a.UserID, b.Act1, b.Act2 from b left join a on a.UserID = b.UserID where a.DepartA = 'YX' order by a.UserID
#8
贴建表及插入记录的SQL,及要求结果出来看看
所有人员的最后两条行为信息:什么标准,SEQ最大?
select b.* from b
inner join a on a.UserID=b.UserID
where 2>(select count(*) from b where a.UserID=UserID and a.seq<seq)
and DepartA='YX'
#9
别名弄错了
select b1.* from b b1
inner join a on a.UserID=b1.UserID
where 2>(select count(*) from b where b1.UserID=UserID and b1.seq<seq)
and a.DepartA='YX'
select b1.* from b b1
inner join a on a.UserID=b1.UserID
where 2>(select count(*) from b where b1.UserID=UserID and b1.seq<seq)
and a.DepartA='YX'
#10
select *
from A inner join B x on a.UserID=x.UserID
where DepartA='YX'
and 2>(select count(*) from B where UserID=x.UserID and SEQ>x.SEQ)
#1
mysql是不支持cross apply语法的
SELECT
a.col1, b.col1, b.col2
FROM ta a,tb b
WHERE b.col3 = a.col1
GROUP BY a.col1;
SELECT
a.col1, b.col1, b.col2
FROM ta a,tb b
WHERE b.col3 = a.col1
GROUP BY a.col1;
#2
MYSQL 没有CROSS APPLY,你要达到什么目的,
贴建表及插入记录的SQL,及要求结果出来看看
贴建表及插入记录的SQL,及要求结果出来看看
#3
表结构如下:
A是统计表,字段如下:
UserID,DepartA(部门), TJA,TJB
B是流水表
SEQ(自增), UserID, Act1,Act2
现在结果要求:从A和B表中加载所属部门为‘YX’ 所有人员的最后两条行为信息。
A是统计表,字段如下:
UserID,DepartA(部门), TJA,TJB
B是流水表
SEQ(自增), UserID, Act1,Act2
现在结果要求:从A和B表中加载所属部门为‘YX’ 所有人员的最后两条行为信息。
#4
select b.UserID, b.Act1, b.Act2 from b left join a on a.UserID = b.UserID where a.DepartA = 'YX' order by b.SEQ desc limit 2;
我刚学不久,不知道对不!
我刚学不久,不知道对不!
#5
楼上不对,坐等牛逼写法。
#6
贴建表及插入记录的SQL,及要求结果出来看看
#7
select a.UserID, b.Act1, b.Act2 from b left join a on a.UserID = b.UserID where a.DepartA = 'YX' order by a.UserID
#8
贴建表及插入记录的SQL,及要求结果出来看看
所有人员的最后两条行为信息:什么标准,SEQ最大?
select b.* from b
inner join a on a.UserID=b.UserID
where 2>(select count(*) from b where a.UserID=UserID and a.seq<seq)
and DepartA='YX'
#9
别名弄错了
select b1.* from b b1
inner join a on a.UserID=b1.UserID
where 2>(select count(*) from b where b1.UserID=UserID and b1.seq<seq)
and a.DepartA='YX'
select b1.* from b b1
inner join a on a.UserID=b1.UserID
where 2>(select count(*) from b where b1.UserID=UserID and b1.seq<seq)
and a.DepartA='YX'
#10
select *
from A inner join B x on a.UserID=x.UserID
where DepartA='YX'
and 2>(select count(*) from B where UserID=x.UserID and SEQ>x.SEQ)