Some of the questions we went to gather in the United States today

Source: Internet
Author: User
1. Write a function to put 1,2,3,4,5,6 randomly into an array, 3 cannot be in the third position, 5 and 6 cannot be next to each other.

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);p Rint_r (Sort_test ($array));

2, write a function to implement the string $str= "Asdfasflasdfopafdsa", the first occurrence of the letter.
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 (+) 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 that queries the product name, the total number of sales, and the total number of sales in the T1-t2 period from highest to lowest.

My approach:

Select  products.product_name,  number.numfrom ((SELECT         product_id,         sum (num) as num from       orders         WHERE orders.create_at between {$t 1} and {$t 2}       GROUP by product_id) as number) INNER JOIN products on products.product_id = Number.product_idorder by Number.num DESC;
These three questions the impression is more profound other not quite remembers, the answer is writes according to my own practice, the wrong place please correct me

The above on the introduction of today to gather the United States several face questions, including the aspects of the content, I hope that the PHP tutorial interested in a friend 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.