SQL 语句

Posted ⬆️小马哥⬆️

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL 语句相关的知识,希望对你有一定的参考价值。

SELECT a.*, (SELECT count(*) FROM user_group AS b WHERE a.sid = b.gid) AS count, (SELECT c.name FROM riki.market_apps AS c WHERE a.owner
= c.app) AS mafeng, a.owner in ("i1") AS isione FROM `groups` AS a WHERE name LIKE ‘%%‘ ORDER BY a.id LIMIT 200 OFFSET 0;

SELECT a.*,b.fullname,b.email,b.login_at FROM app_member a left join users b on a.uid=b.username WHERE a.app = ‘3gpjfqge85u6626f‘;
// 删除组
DELETE FROM app_member WHERE type=‘group‘ AND uid=‘10pjvf3bjeeu‘;

// 删除角色
DELETE FROM app_member WHERE type=‘role‘ AND uid=‘‘;

//查询
SELECT a.*,b.fullname,b.email,b.login_at FROM app_member a left join users b on a.uid=b.username WHERE a.app = ‘3gpjfqge85u6626f‘;

SELECT * FROM user_group WHERE gid=‘10pjvf3bjeeu‘;

SELECT * FROM `groups` WHERE sid=‘10pjvf3bjeeu‘ AND `owner` = ‘3gpjfqge85u6626f‘;
# left join
SELECT * FROM riki.subscribe_apps a LEFT JOIN `groups` b ON a.id=b.`owner`;

SELECT * FROM `groups` b LEFT JOIN riki.subscribe_apps a ON a.id=b.`owner`;

SELECT a.*, c.name AS app_name, (SELECT count(*) FROM user_group AS b WHERE a.sid = b.gid) AS count
FROM `groups` AS a
LEFT JOIN riki.subscribe_apps c
ON c.id=a.`owner`
WHERE a.name LIKE ‘%%‘ ORDER BY a.id LIMIT 20 OFFSET 100;


SELECT * FROM riki.subscribe_apps where id = ‘f08am4p62q8gludg‘;

SELECT a.sid, a.owner in (‘i1‘) AS isione, a.name, a.description FROM `groups` AS a, user_group AS b,
riki.subscribe_apps AS c
WHERE a.sid = b.gid AND c.id=a.`owner` AND b.uid =‘mafeng‘;

SELECT c.sid, c.description, c.owner in (‘i1‘) AS isione, c.`name`, c.`owner`, d.`name` AS c_instance_name FROM
(SELECT a.sid, a.name, a.description, a.`owner` FROM `groups` AS a, user_group AS b
WHERE a.sid = b.gid AND b.uid =‘mafeng‘) AS c LEFT JOIN
riki.subscribe_apps d
ON d.id=c.`owner`;

SELECT c.sid, c.description, c.owner in (‘i1‘) AS isione, c.`name`, c.`owner`, d.`name` AS c_instance_name FROM
(SELECT a.sid, a.name, a.description, a.`owner`, %s FROM %s AS a, %s AS b WHERE a.sid = b.rid AND b.uid = ? %s) AS c
LEFT JOIN
riki.subscribe_apps d
ON d.id=c.`owner`;

SELECT a.*, (SELECT count(*) FROM user_group WHERE gid =‘10pjvgnloaua‘) AS count, c.`name` AS c_instance_name FROM `groups` AS a
LEFT JOIN riki.subscribe_apps c
ON c.id=a.`owner`
WHERE a.sid =‘10pjvgnloaua‘;

以上是关于SQL 语句的主要内容,如果未能解决你的问题,请参考以下文章

sql语句时间排序 sql语句按照时间排序

带参数的sql语句!不懂

写出查询的SQL语句

使用sql语句查询日期的方法

如何查找MySQL中查询慢的SQL语句

如何查找MySQL中查询慢的SQL语句