赞
踩
请对附加的SQL查询添加筛选条件,仅显示在加州居住且消费总额排名前10位的客户。
“SELECT customer_name, SUM(order_total) AS total_spent FROM orders GROUP BY customer_name ORDER BY total_spent DESC;”
SELECT customers.customer_name, orders.order_date, order_details.product_name, order_details.quantity
FROM customers
JOIN orders ON customers.customer_id = orders.customer_id
JOIN order_details ON orders.order_id = order_details.order_id
WHERE orders.order_total > 1000 AND order_details.product_name LIKE '%chair%';
显示 2022 年 1 月 1 日至 2022 年 3 月 1 日之间的所有订单。 SELECT * FROM orders WHERE
order_date BETWEEN ‘2022-01-01’ AND ‘2022-03-01’;
private static String getString13(String text) {
String regs[] = {"(\\d{4})年(\\d{1,2})月(\\d{1,2})日"};
for (String reg : regs) {
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
String year = matcher.group(1);
String month = String.format("%02d", Integer.parseInt(matcher.group(2)));
String day = String.format("%02d", Integer.parseInt(matcher.group(3)));
return year + "-" + month + "-" + day;
}
}
return "";
}
使用 SQL 更新电子产品分类是electronics的价格,并将价格提高10%。
UPDATE products SET price =
price * 1.1 WHERE category = ‘electronics’;
BITO:
https://share.bito.co/static/share?aid=1edd448a-544c-4526-a96d-59bc04166709
public static String generatorSqlQuery2(String sql, String demand, String table){ String keyword = "",d2=""; if(demand.contains("查询")||demand.contains("select")||demand.contains("筛选")){ keyword = "SELECT * FROM "+table+" "; String d = keyword,text = demand; keyword = getColums(d, text); //第二部分 column // d2 = getColums51(d2, text); //第5部分 set keyword = getColums5(keyword, text, 0); //第5部分 where //第3部分 GROUP BY 总额 keyword = getColums3(keyword, text); //第3部分 column //第4部分 ORDER BY 排名 keyword = getColums4(keyword, text); //第4部分 column }else if(demand.contains("删除数据")||demand.contains("delete")){ keyword = "DELETE"; }else if(demand.contains("删除")||demand.contains("drop")){ keyword = "DROP"; }else if(demand.contains("修改数据")||demand.contains("update")||demand.contains("更新")){ keyword = "UPDATE "; String d = keyword,text = demand; keyword = getColums(d, text); //第二部分 column keyword = getColums51(keyword, text); //第5部分 set keyword = getColums5(keyword, text, 0); //第5部分 where }else if(demand.contains("修改")||demand.contains("alter")){ keyword = "ALTER"; }else if(demand.contains("增加")||demand.contains("insert")){ keyword = "INSERT"; }else if(demand.contains("创建")||demand.contains("create")){ String name = getText5(demand); keyword = "create database if not exists "+name+" character set utf8"; }else if(demand.contains("显示")||demand.contains("show")){ keyword = "SHOW"; }else if(demand.contains("清空")||demand.contains("truncate")){ keyword = "TRUNCATE"; } keyword = keyword+";"; return keyword; }
查询代码的书写顺序和执行顺序
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。