Several interview questions to get together today

Source: Internet
Author: User
: This article mainly introduces several interview questions about going to Jumei today. if you are interested in PHP tutorials, please refer to them. 1. write a function to randomly place 1, 2, 3, 4, 5, and 6 in an array. 3 cannot be in the third position, and 5 and 6 cannot be in the same position.

function sort_test($array){    while(true) {        shuffle($array);        $temp = array_flip($array);        if ($array[2] != 3 && 1 != abs($temp[5] - $temp[6])) {            return $array;        }    }}$array = array(1,2,3,4,5,6);print_r(sort_test($array));

2. write a function to implement the first occurrence of a letter in the string $ str = "asdfasflasdfopafdsa.
function get_target_letter($str){    $i = 0;    $array = array();    while(isset($str[$i])) {        $array[$str[$i]] = isset($array[$str[$i]]) ? $array[$str[$i]] + 1 : 1;        $i ++;    }    foreach($array as $key=>$val) {        if ($val == 1) {            return $key;        }    }    return false;}echo get_target_letter('asdfastflasdfopafdsa');
3. there are two tables:
CREATE TABLE products (  product_id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,  product_name VARCHAR(64) NOT NULL);CREATE TABLE orders (  product_id INT UNSIGNED NOT NULL ,  create_at INT UNSIGNED NOT NULL,  num INT UNSIGNED NOT NULL );
 

Write an SQL statement to query the product name, total sales volume, and sort by the total sales volume from high to low in the T1-T2 period.

My practices:

SELECT  products.product_name,  number.numFROM ((SELECT         product_id,         sum(num) AS num       FROM orders         WHERE orders.create_at BETWEEN {$t1} AND {$t2}       GROUP BY product_id) AS number) INNER JOIN products ON products.product_id = number.product_idORDER BY number.num DESC;
These three questions are quite impressive. others do not quite remember. The answer is based on my own practice. please correct me if it is not correct.

The above section describes several interview questions about going to Jumei today, including some content. I hope my friends who are interested in PHP tutorials will be helpful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.