问题描述
首先我使用Access数据库和ole db conn。
我有桌子预订:
+ ------------ + -------------- +
| no_booking | date_service |
+ ------------ + -------------- +
| AN02091701 | 02/09/2017 |
| AN02091702 | 02/09/2017 |
| AN02091703 | 02/09/2017 |
| AN02091703 | 02/09/2017 |
| AN03091701 | 03/09/2017 |
| AN03091702 | 2017/03/09 | ---?找到AN03091702
| AN04091701 | 04/09/2017 |
| AN04091702 | 04/09/2017 |
| AN05091701 | 05/09/2017 |
| AN05091702 | 05/09/2017 |
| AN05091703 | 05/09/2017 |
| AN07091701 | 07/09/2017 |
+ ------------ + -------------- +
我想要预订服务..
我正在使用日期选择器来选择日期作为请求成员(确切地是随机的)。 。
我想要的条件 - >在一天内只有< 4 no_booking
接下来我试着找到有< b的日期4 no_booking自动创建no_booking。
假设我们现在没有日期所在的位置< 4 no_booking ...
如何找到包含< 4 no_booking(日期是03/09/2017因为有2个no_booking),
然后在03/09/2017选择no_booking的lastindex ----> ;完全是AN03091702。使用最快的查询?
希望我解释正确,但对不起我的英语..
谢谢。 ...
我的尝试:
first I'm using Access database and ole db conn.
I have table Booking :
+------------+--------------+
| no_booking | date_service |
+------------+--------------+
| AN02091701 | 02/09/2017 |
| AN02091702 | 02/09/2017 |
| AN02091703 | 02/09/2017 |
| AN02091703 | 02/09/2017 |
| AN03091701 | 03/09/2017 |
| AN03091702 | 03/09/2017 | ---? find AN03091702
| AN04091701 | 04/09/2017 |
| AN04091702 | 04/09/2017 |
| AN05091701 | 05/09/2017 |
| AN05091702 | 05/09/2017 |
| AN05091703 | 05/09/2017 |
| AN07091701 | 07/09/2017 |
+------------+--------------+
I want make bookingservice ..
i'm using date picker to select date as request member (exactly will be randomly)..
condition that i want --> in one day only have < 4 no_booking
next i try to find the date which have < 4 no_booking to create no_booking automatic.
assumtion that we don't now where the date have < 4 no_booking ...
how to find the top date that contain < 4 no_booking ( the date is 03/09/2017 because have 2 no_booking),
then select the lastindex of no_booking in 03/09/2017 ----> exactly AN03091702 . using fastest query ?
Hope I explain correctly,but sorry about my english ..
Thanks ....
What I have tried:
select no_booking,datebo from booking group by no_booking,datebo having count (datebo) < 3
推荐答案
SELECT nobooking,datebo FROM booking WHERE nobooking='AN30081702' GROUP BY nobooking,datebo HAVING COUNT(datebo) < 3;
如果列名包含空格(No Booking而非nobooking)或一段时间,你必须用引号或括号括起来。如果要返回表中的所有列,还可以使用 *
占位符:
If the column name contains a space ("No Booking" instead of "nobooking") or a period, you have to enclose it by quotes or brackets. If you want to return all columns from a table, you can also use the *
placeholder:
SELECT * FROM booking WHERE [No booking]='AN30081702' GROUP BY [No booking],[datebo.] HAVING COUNT([datebo.]) < 3;
正如您所见,在数据库表和列中使用空格和点是个坏主意名。如果可能,请避免使用它们(以及SQL关键字)作为名称。
As you can see it is a bad idea to uses spaces and dots in database table and column names. Avoid them (and SQL keywords too) as names if possible.
这篇关于如何选择特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!