a表1,2,3.
b表2,3,4
全连接结果:
1,null
2,2
3,3
null,4
where 选中带有null的值
1,null
null,4
b表2,3,4
全连接结果:
1,null
2,2
3,3
null,4
where 选中带有null的值
1,null
null,4
2019-01-24
表a,id为1,2,3
表b,id为2,3,4
想找出不和b表id相等的数据。
(notin方法)
select * from a
where a.id not in (
select id from b
)
(leftjoin方法)
(1)
select * from a
left join b
on a.id=b.id
查出1,null ;2,2;3,3三条数据
上面sql加上where限制,where b.id=null, 就只剩下一条id=1的数据
表b,id为2,3,4
想找出不和b表id相等的数据。
(notin方法)
select * from a
where a.id not in (
select id from b
)
(leftjoin方法)
(1)
select * from a
left join b
on a.id=b.id
查出1,null ;2,2;3,3三条数据
上面sql加上where限制,where b.id=null, 就只剩下一条id=1的数据
2019-01-24
UPDATE `取经四人组`
SET ending='齐天大圣' WHERE `取经四人组`.user_name in
(SELECT * FROM(SELECT `取经四人组`.user_name
FROM `取经四人组` INNER JOIN `孙悟空的朋友` ON `取经四人组`.user_name = `孙悟空的朋友`.user_name )as temp)
SET ending='齐天大圣' WHERE `取经四人组`.user_name in
(SELECT * FROM(SELECT `取经四人组`.user_name
FROM `取经四人组` INNER JOIN `孙悟空的朋友` ON `取经四人组`.user_name = `孙悟空的朋友`.user_name )as temp)
2018-10-18
这个sql分组求top n应该是有问题的,如果一个人在3个不同时间段kill的人相同,比如都kill了一个人,那么就会取不出结果了。
2018-08-11
SELECT
t1.id,
t1.NAME,
t2.num,
count( 1 ) cnt
FROM
tbl_goods t1
LEFT JOIN tbl_sale t2 ON t1.id = t2.goods_id
LEFT JOIN tbl_sale t3 ON t2.goods_id = t3.goods_id
WHERE
t2.num <= t3.num
GROUP BY
1,
2,
3
HAVING
cnt <= 2
---------------------------------
join关联查询
t1.id,
t1.NAME,
t2.num,
count( 1 ) cnt
FROM
tbl_goods t1
LEFT JOIN tbl_sale t2 ON t1.id = t2.goods_id
LEFT JOIN tbl_sale t3 ON t2.goods_id = t3.goods_id
WHERE
t2.num <= t3.num
GROUP BY
1,
2,
3
HAVING
cnt <= 2
---------------------------------
join关联查询
2018-07-08
前面说找自己问题的,你真是够了,老师前面明确写着is null,后面自己写错了,然后让我们找自己的问题?开玩笑吧
2018-06-28