SELECT custid, MAX(STR_TO_DATE(a.order_date,'%Y-%m-%d')) order_date
FROM order_table as a
GROUP BY custid
ORDER BY custid DESC;
[/code]
3、用一条SQL语句查出订单表(product表)购买的每类产品付款都大于60元的客户姓名;
![](https://img2018.cnblogs.com/blog/1712945/201906/1712945-20190627134141177-1576213440.png)
此题的考察点有where 和 group by:如下的SQL语句可以查询出每一类产品对应付款都大于60元的客户姓名:
```code
SELECT product as 产品,name as 客户 FROM order_product
WHERE payment > 60
GROUP BY product,name
ORDER BY product;
[/code]
![](https://img2018.cnblogs.com/blog/1712945/201906/1712945-20190627151205698-2126776990.png)
4、请问‘SELECT 1/3’运行后能否得到结果0.33,如不能请给出正确的代码;
得到的结果是0.3333,正确的代码应该是
```code
SELECT ROUND(1/3,2)
[/code]
5、根据如下订单表,请使用sql语法,按购买时间统计出每天的新客人数和老客人数;
![](https://img2018.cnblogs.com/blog/1712945/201906/1712945-20190627152616979-917969802.png)
名词定义如下:
新客:当天有购买,且之前没有购买的人为新客,新客人数+1;
老客:当天有购买,且之前也有购买的人为老客,老客人数+1;
6、根据如下左表具有3层关系的类目表,请使用sql语法,将数据展现成右表形式:
![](https://img2018.cnblogs.com/blog/1712945/201906/1712945-20190628135100440-1056243598.png)
转载于:https://www.cnblogs.com/lsyb-python/p/11083977.html
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210608151750993.gif)