Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get data from 2 tables
Message
 
 
À
08/02/2019 19:07:16
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2008 R2
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01666006
Message ID:
01666198
Vues:
52
>>>Sir you used your following codes
>>>
>>>
>>>SELECT Date, DatePart(hour,Date) as Hr, reading
>>>FROM bin1_empty A
>>>WHERE EXISTS( 
>>>(SELECT Min(Date) as date_B
>>>FROM bin1_empty B
>>>WHERE DatePart(hour,A.Date) = DatePart(hour,B.Date) 
>>>HAVING B.Date_B = A.Date)
>>>OR EXISTS(
>>>SELECT Min(Date) as date_C
>>>FROM bin1 C
>>>WHERE DatePart(hour,A.Date) = DatePart(hour,C.Date)
>>>HAVING C.Date_C = A.Date)
>>>
>>>
>>>but it has error shown in image.
>>
>>
>>I think there was one ) too much:
>>
>>
>>SELECT Date, DatePart(hour,Date) as Hr, reading
>>FROM bin1_empty A
>>WHERE EXISTS( 
>>SELECT Min(Date) as date_B
>>FROM bin1_empty B
>>WHERE DatePart(hour,A.Date) = DatePart(hour,B.Date) 
>>HAVING B.Date_B = A.Date)
>>OR EXISTS(
>>SELECT Min(Date) as date_C
>>FROM bin1 C
>>WHERE DatePart(hour,A.Date) = DatePart(hour,C.Date)
>>HAVING C.Date_C = A.Date)
>>
>
>
>Sir it has still error like shown in image.

Indeed, in the having clause you must refer to the Expression and not to the field name. Therefore C.Date_C does not exist. My fault: It should have been Having MIN(date):

Also I would prefix all field names with the Alias to make sure it is understandable.
SELECT A.Date, DatePart(hour,A.Date) as Hr, A.Reading
FROM bin1_empty A
WHERE EXISTS( 
SELECT Min(B.Date) as date_B
FROM bin1_empty B
WHERE DatePart(hour,A.Date) = DatePart(hour,B.Date) 
HAVING Min(B.Date) = A.Date)
OR EXISTS(
SELECT Min(C.Date) as date_C
FROM bin1 C
WHERE DatePart(hour,A.Date) = DatePart(hour,C.Date)
HAVING Min(C.Date) = A.Date)
Christian Isberner
Software Consultant
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform