[Solved] How to list all ratings received by user

Ok, some people here thinks is funny to downvote a post, well i’m posting the solution cause i know that it can be helpfull to. This is the Query i built: SELECT u.usuario, u.id_usuario, d.id, v.valoracion, v.fecha FROM icar_valoraciones v JOIN icar_dibujos d ON v.id_dibujo = d.id JOIN icar_usuarios u ON v.id_quien = u.id_usuario WHERE … Read more

[Solved] SQL not finding results

This is or was an issue with the With Adoquery2 do begin … end when using name in the sql, it was really getting adoquery2.name not the var name. I fixed this by changing name to Cname had no more issues after that. 1 solved SQL not finding results

[Solved] Using distinct for specific column in oracle

In your example the query returns distinct values for the combination of COLA and COLB. Examine the syntax: Note, that DISTINCT/UNIQUE/ALL can be only placed after SELECT and before of the first expression in the select list. The documentation says that:https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10002.htm DISTINCT | UNIQUE Specify DISTINCT or UNIQUE if you want the database to return … Read more

[Solved] Convert text to system date format [duplicate]

EDIT From SQL Server 2012 and later you might use the FORMAT function if you want to force a date into a formatted text: https://msdn.microsoft.com/en-us/library/hh213505.aspx With earlier versions you might use something like this: DECLARE @d DATETIME=GETDATE(); DECLARE @TargetFormat VARCHAR(100)=’DD/MM/YYYY’; SELECT CONVERT(VARCHAR(100),@d, CASE @TargetFormat WHEN ‘MM/DD/YYYY’ THEN 101 WHEN ‘DD/MM/YYYY’ THEN 103 –add all formats … Read more

[Solved] Query to return record value in column instead of row?

SELECT c.ClientID, c.LastName, c.FirstName, c.MiddleName, CASE WHEN cudf.UserDefinedFieldFormatULink = ’93fb3820-38aa-4655-8aad-a8dce8aede’ THEN cudf.UDF_ReportValue AS ‘DA Status’ WHEN cudf.UserDefinedFieldFormatULink = ‘2144a742-08c5-4c96-b9e4-d6f1f56c76’ THEN cudf.UDF_ReportValue AS ‘FHAP Status’ WHEN cudf.UserDefinedFieldFormatULink = ‘c3d29be9-af58-4241-a02d-9ae9b43ffa’ THEN cudf.UDF_ReportValue AS ‘HCRA Status’ END INTO #Temp FROM Client_Program cp INNER JOIN client c ON c.ulink = cp.clientulink INNER JOIN code_program p ON p.ulink = cp.programulink … Read more

[Solved] SQL Join with unique rows

Ok, let’s see if this answer suits your request. SELECT a.EMPLID,a.DEDCD, to_char(a.EFFDT,’YYYY-MM-DD’) EFFDT, b.DEDCD as DEDCD2,GTN FROM ( select EFFDT,GTN,EMPLID,DEDCD, row_number() over (partition by EMPLID order by DEDCD) rn from table1 ) A LEFT OUTER JOIN ( select EFFDT,EMPLID,DEDCD, row_number() over (partition by EMPLID order by DEDCD) rn from table2 ) B ON ( A.EMPLID=B.EMPLID … Read more

[Solved] Print name of all activities with neither maximum nor minimum number of participants

You can use window functions if your mysql version is 8 or above select activity from (select activity, count(*) as cnt, max(count(*)) over () as maximum_cnt, min(count(*)) over () as minimum_cnt from friends group by activity) mytable where cnt not in (maximum_cnt, minimum_cnt); 4 solved Print name of all activities with neither maximum nor minimum … Read more

[Solved] Filter out records that are not in this date format oracle

You can use an inline function to check if the date is valid. Like this: WITH FUNCTION is_valid_date (date_str_i VARCHAR2, format_i VARCHAR2) RETURN VARCHAR2 /* check if date is valid */ AS l_dummy_dt DATE; BEGIN SELECT TO_DATE(date_str_i,format_i) INTO l_dummy_dt FROM DUAL; RETURN ‘Y’; EXCEPTION WHEN OTHERS THEN RETURN ‘N’; END; dates AS ( SELECT ‘0201-05-31 … Read more

[Solved] SQL Query to Transpose Column Counts to Row Counts

These type of queries are easier to make with an aim of GROUP BY, like this: Select case when profile.foo ~* ‘5.0.2195’ then ‘Win2k’ when profile.foo ~* ‘5.1.2600’ then ‘WinXP’ when profile.foo ~* ‘5.2.3790’ then ‘W2k3’ when (profile.foo ~* ‘6.0.6000’ or profile.foo ~* ‘6.0.6001’ or profile.foo ~* ‘6.0.6002’) then ‘Vista’ when (profile.foo ~* ‘6.1.7600’ or … Read more

[Solved] Grouping ranges of data

Since we’re sorting by StartDate and EndDate, we should be able to use the minimum of this and all future start dates and the maximum of this and all past end dates. This is just one more step beyond what Bert Wagner published. DROP TABLE IF EXISTS #OverlappingDateRanges; CREATE TABLE #OverlappingDateRanges (StartDate date, EndDate date); … Read more

[Solved] PHP MYSQL INSERT help no errors [closed]

The following worked for me: I have to point out that you can’t use $postedOn = now(); as a variable to post the current time/date. It needs to be entered as part of the VALUES I.e.: VALUES(:videoId,:username,NOW())”; Do note that I used $pdo as the connection variable. <?php $mysql_hostname=”xxx”; $mysql_username=”xxx”; $mysql_password = ‘xxx’; $mysql_dbname=”xxx”; try … Read more

[Solved] SQL grouping on time interval

WITH changes AS ( SELECT “DATE”, CASE WHEN LAG( “DATE” ) OVER ( ORDER BY “DATE” ) + INTERVAL ‘5’ MINUTE = “DATE” THEN 0 ELSE 1 END AS has_changed_group FROM TEST ), grps AS ( SELECT “DATE”, SUM( has_changed_group ) OVER ( ORDER BY “DATE” ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) AS … Read more

[Solved] Merge two queries to get the combined value in SQL

select `EmpsID`, `CAT`, `CHK_DATE`, SUM(AMOUNT) as CurrentAmount,SUM(UNITS) as CurrentUnits ,sum(case when date(`CHK_DATE`) = ‘2016-11-12’ then AMOUNT else 0 end) as ‘2016-11-12Amount’ , ,sum(case when date(`CHK_DATE`) = ‘2016-11-12’ then UNITS else 0 end) as ‘2016-11-12Units’ , from `pays` where `EmpsID` = ‘SEMLAD01’ and `CAT` in (‘Salary Pay’, ‘TRUCK ALLOWANCE’, ‘Expense Reimbursement’, ‘BONUS (Accrued)’, ‘Phone Reimbursement’)and date(`CHK_DATE`) … Read more