Sql queries
- Query to fetch links of a particular user
- To fetch all categories and number of links in the category for a particular user :
- SELECT l.`categoryId` as `Category Id`,lc.title as `Category Name`,count(*) as `Number of links` FROM `save-app`.`links` l inner join
`link-categories` lc on lc.`key` = l.categoryId
where l.createdBy = <user-id-of-the-user>
group by categoryId
- SELECT l.`categoryId` as `Category Id`,lc.title as `Category Name`,count(*) as `Number of links` FROM `save-app`.`links` l inner join
- To fetch all the thumbnail text for a particular category:
- select l.title as `Link Title`,categoryId as `Category ID`,lc.title as `Category Name` from `links` l
inner join `link-categories` lc on lc.`key`= l.categoryId
where l.createdBy = 12
order by l.categoryId
- select l.title as `Link Title`,categoryId as `Category ID`,lc.title as `Category Name` from `links` l
- To fetch all categories and number of links in the category for a particular user :
- Query to fetch total number of referrals done by users
- SELECT R.userId as `User Id`,U.referalCode as `Referral Code`,count(*) as `Total Referrals`
FROM `referred-users` R, users U
where R.userId = U.key group by R.userId
- SELECT R.userId as `User Id`,U.referalCode as `Referral Code`,count(*) as `Total Referrals`
- Query to see all different types of logins
- SELECT provider as `Login Type`,count(*) as `Number of logins` FROM `save-app`.users
group by provider
- SELECT provider as `Login Type`,count(*) as `Number of logins` FROM `save-app`.users
- Query to see images with and without thumbnail
- To see all links with and without images
- SELECT link,title,
CASE WHEN image IS NOT NULL THEN 'Image Found'
ELSE 'Image Not Found'
END AS image
FROM links;
- SELECT link,title,
- To see total number of links with and without images
- SELECT CASE WHEN image IS NOT NULL THEN 'With Image'
ELSE 'Without Image'
END AS `Link Type`,
COUNT(*) AS `Number of Links`
FROM links
GROUP BY CASE WHEN image IS NOT NULL THEN 'With Image'
ELSE 'Without Image'
END;
- SELECT CASE WHEN image IS NOT NULL THEN 'With Image'
- To see total number of links with and without images based on category
- select lc.`key` as `Category ID`,lc.title as `Categories Without Image`,count(*) as `Number of Links`
from `link-categories` lc,links l
where l.image is null and
l.categoryId = lc.`key`
group by l.categoryId
- select lc.`key` as `Category ID`,lc.title as `Categories Without Image`,count(*) as `Number of Links`
- To see all links with and without images
No Comments