面试/笔试经历--SQL(括号匹配问题)(jdk底层SuString)---weimob

本文分享了SQL中查询成绩大于80分学生姓名的方法,包括去除重复项及计算平均成绩,同时介绍了Java中栈的应用及字符串子串的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一张数据表



1.查询所有成绩大于80分的学生的名字

select DISTINCT a.name from grade a 

where a.name not in (

select DISTINCT s.name from grade s 

where s.score < 80

)



加上DISTINCT(截然不同的) 意义为去掉重复项   在里面查询的表中 如果查到的是两个小红 所以里面的也要用到DISTINCT



2.查询平均成绩大于80分的学生姓名

select a.name,a.avg from (

select name,AVG(score) as avg from grade group by name

) a

where a.avg >80


注意:在AVG函数之后,要加上as avg 取上一个名字来代称 否则会报错

其他的类似于 最大值最小值 取不同的函数即可 MIN()  MAX() 等等


一个经常见到的编程题

(从这个时候我才知道了java也是有stack栈的,枉费我学习java近乎两年,学习不精,实在该检讨)


那么接下来的问题,就与栈有关了 

很常见的编程题 关于括号匹配 

import java.util.Stack;
public class StackProblem
{
    public static void main(String[] args)
    {
        String str = "(())、()";
        boolean flag= new StackProblem().check(str);
        System.out.println("这个字符串为:"+flag);
    }
    
    
    public boolean check(String str){
        int length = str.length();
        Stack<Character> stack = new Stack<Character>();
        for(int i=0;i<length;i++){
            if(str.charAt(i)==')'){
                stack.pop();
            }else if(str.charAt(i)=='('){
                stack.push(str.charAt(i));
            }else if(str.charAt(i)=='、'){
                //则遇到的就是、了 此时如果栈里有元素 那么一定不匹配 没有元素就可以继续了
               if(!stack.empty()){
                   //非空 直接返回false
                   return false;
               }
            }
        }
        if(stack.empty()){
            return true;
        }else{
            return false;
        }
        
    }
}
3.String.substring(beginIndex,endIndex);

那么这就是考你的JDK底层到底看了多少东西了呢,实话是如果真没看过,那是真不会。最常见的也说不上来,先把遇到的贴上去把。

  /**
     * Returns a string that is a substring of this string. The
     * substring begins at the specified {@code beginIndex} and
     * extends to the character at index {@code endIndex - 1}.
     * Thus the length of the substring is {@code endIndex-beginIndex}.
     * <p>
     * Examples:
     * <blockquote><pre>
     * "hamburger".substring(4, 8) returns "urge"
     * "smiles".substring(1, 5) returns "mile"
     * </pre></blockquote>
     *
     * @param      beginIndex   the beginning index, inclusive.
     * @param      endIndex     the ending index, exclusive.
     * @return     the specified substring.
     * @exception  IndexOutOfBoundsException  if the
     *             {@code beginIndex} is negative, or
     *             {@code endIndex} is larger than the length of
     *             this {@code String} object, or
     *             {@code beginIndex} is larger than
     *             {@code endIndex}.
     */
    public String substring(int beginIndex, int endIndex) {
        if (beginIndex < 0) {
            throw new StringIndexOutOfBoundsException(beginIndex);
        }
        if (endIndex > value.length) {
            throw new StringIndexOutOfBoundsException(endIndex);
        }
        int subLen = endIndex - beginIndex;
        if (subLen < 0) {
            throw new StringIndexOutOfBoundsException(subLen);
        }
        return ((beginIndex == 0) && (endIndex == value.length)) ? this
                : new String(value, beginIndex, subLen);
    }

但是整个提炼下来,我绝得面试 的人其实看的主要还是就一行代码

return ((beginIndex == 0) && (endIndex == value.length)) ? this
                 : new String(value, beginIndex, subLen);


自己尝试一下 return ((beginIndex==0) && (endIndex==value.length) ) ?  this 

                                     : new String(value,beginIndex,sublen);

以上.......校招的漫长之路,就这样吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值