I need a Query that without any changes work on these three different database server : MySQL, MSSQL, PostgreSQL . In this query i have to calculate a column with the following expression that work correctly on MySQL :
Code:
COUNT(DISTINCT field_char,field_int,field_date) AS costumernum
The fields in the distinct are of different type :
Code:
field_char = character
field_int = integer
field_date = datetime
The expression work correctly on MySQL but i get an error when i try to execute it on Sql Server or PostgreSQL (the problem is that the count function doesn't accept 3 arguments of different type on MSSQL/PostgreSQL), is there a way to achieve the same result with an expression that work in each of these database server (SQL Server, MySQL, PostgreSQL ) ?
I've tried also in another manner : including the count on a subquery, with this approach the query should work on every database server type, but the problem is that from the inner query i can't get the value of a field in the parent query, for example :
Code:
SELECT t0.description,t0.depnum
(select count(*) from (
select distinct f1, f2, f3 from salestable t1
where t1.depnum = t0.depnum
) a) AS numitems
FROM salestable t0
In the query above t0.depnum isn't recognized as a valid field in the subquery,
i get an error , how can i get the value of the parent query ? Is there a way ?
Thanks.