
MYSQL
???/cy
算法工程师,日常分享多模态领域的前沿成果,与自己工程经验的总结,问道~大模型
展开
-
MySQL|EXISTS 运算符
Table:-- Select clients that have an invoiceSELECT *FROM clients cWHERE EXISTS( SELECT client_id FROM invoices WHERE client_id = c.client_id)output:原创 2021-04-19 13:36:57 · 147 阅读 · 0 评论 -
MySQL|相关子查询 Correlated subqueries
--Select employees whose salary is above the average in their office-- GET invoices that are larger than the client's average invoice amountSELECT *FROM invoices iWHERE invoice_total > ( SELECT AVG(invoice_total) FROM invoices WHERE clien原创 2021-04-19 11:47:29 · 228 阅读 · 0 评论 -
MySQL|ANY关键字
--Select client with at least two invoices__________________________________________count___________________________________________________看一下COUNT的用法:SELECT client_id, COUNT(*)FROM invoicesGROUP BY client_idOutput:_________________________原创 2021-04-19 10:56:18 · 248 阅读 · 0 评论 -
MySQL|ALL 关键字
-- Select invoices larger than all invoices of client 3USE sql_invoicing;SELECT *FROM invoicesWHERE invoice_total >( SELECT MAX(invoice_total) FROM invoices WHERE invoice_id = 3)Other solution(with ALL 关键字):USE sql_invoicing;SELEC原创 2021-04-19 10:35:59 · 497 阅读 · 0 评论 -
MySQL| Subqueries vs joins
-- Find customers who have ordered lettuce(id = 3)-- Select customer_id, first_name, last_nameSELECT *FROM customers-- 在下面的子查询中, 返回订购了生菜的顾客的IDWHERE customer_id IN ( SELECT o.customer_id FROM order_items oi JOIN orders o USING(orde...原创 2021-04-19 10:23:06 · 123 阅读 · 0 评论 -
MySQL|IN运算符
-- Find the products that have never been orderedUSE sql_store;SELECT *FROM productsWHERE product_id NOT IN( SELECT DISTINCT product_id FROM order_items)Output:-------------------------------------------------------------------作业---.原创 2021-04-18 19:13:23 · 116 阅读 · 0 评论 -
MySQL|编写子查询
-- FIND products that are more-- expensive than Lettuce(id = 3)SELECT *FROM productsWHERE unit_price > ( SELECT unit_price FROM products WHERE product_id = 3)-- (这里面是lettuce的价格)Output:-------------------------------------------.原创 2021-04-18 18:55:11 · 79 阅读 · 0 评论 -
MySQL| With rollup
SELECT pm.name AS payment_method, sum(amount) AS totalFROM payments p JOIN payment_methods pm ON p.payment_method = pm.payment_method_idGROUP BY pm.name WITH ROLLUPOutput:原创 2021-04-18 18:39:32 · 85 阅读 · 0 评论 -
MySql |TheHAVING Clause
SELECT client_id, SUM(invoice_total) AS total_salesFROM invoicesGROUP BY client_id -- 分组HAVING total_sales > 500-- 使用having子句:为了在分组之后进行筛选Output:-------------------------------------------------作业-----------------------------------..原创 2021-04-18 18:15:03 · 203 阅读 · 0 评论 -
MySQL GROUP BY 子句| The GROUP BY Clause
SELECT client_id, SUM(invoice_total) AS total_salesFROM invoicesWHERE invoice_date >= '2019-07-01'GROUP BY client_id -- 看每一个顾客花的钱ORDER BY total_sales DESC -- 按照total_sales 的降序来显示 看看谁花的多-- 注意顺序 永远是 FROM WHERE GROUP_BY ORDER_BY 这个顺序哈Ou.原创 2021-04-17 16:37:00 · 113 阅读 · 0 评论