[Solved] SQL query a percentage [closed]

GROUP BY and HAVING Class 101 SELECT student_id, SUM(CAST(pass AS INT)) * 100 / COUNT(course_id) as pass_rate FROM MyTable GROUP BY student_id HAVING(sum(cast(pass as int)) * 100 / count(course_id)) > 95 solved SQL query a percentage [closed]

[Solved] Want to get drop down value on php sql query without page refresh

Use ajax $.ajax({ url: “fetchlist.php”, dataType: ‘json’, success: function(response){ // Here, you may bind response with your select HTML } }); You may either return json from your php file and create DOM elements in response. Or, you may create HTML version and return as response. Suggestion will be to use JSON for better flexibility. … Read more

[Solved] 1 x chen hyd 2 y bang mum [closed]

Use UNION like: SELECT id,name,add1 from mytable UNION SELECT id,name,add2 from mytable EDIT: for better performance you can use UNION ALL instead, that will give you the same result: SELECT id,name,add1 from mytable UNION ALL SELECT id,name,add2 from mytable 4 solved 1 x chen hyd 2 y bang mum [closed]

[Solved] T-SQL | SQL-Server Pivot [closed]

Try: select Agent, max(case when `desc` = ‘Total’ then ColValue else 0 end) Total, max(case when `desc` = ‘Replaced’ then ColValue else 0 end) Replaced from tbl group by Agent Demo sqlfiddle 1 solved T-SQL | SQL-Server Pivot [closed]

[Solved] SQL Server : how to sum? [closed]

SELECT SUM(Value) FROM TableName; Using a GROUP BY (per your comment above) is when you want things grouped over a subset. In this case, a group by would return the same info you’ve sampled, because there’s no groups to sum on the desc field… however if you had two “e” descriptions (let’s say 40 for … Read more

[Solved] How to improve performance of this query [closed]

Few ideas below Remove as many left joins as possible. Use inner joins where-ever possible. Remove sub-query to get ISerialNumber. Get this later in wrapper query. Create indexes on columns in the WHERE clause if not already existing. Do not use this way of date comparison. Imagine this conversion for every row in your result … Read more

[Solved] Convert month and year columns to a date column with additional string concatination

Assuming your are using date and MSSQL2012+: SELECT UPPER( FORMAT(CONVERT(datetime, ‘2017-02-01′,121),’MMM’)) + ‘-‘ +RIGHT(CAST( YEAR( CONVERT(datetime, ‘2017-02-01’,121)) AS VARCHAR(4)),2) M_DELIVERY , ‘DELIVERY FOR ‘ +UPPER( FORMAT(CONVERT(datetime, ‘2017-02-01′,121),’MMM’))+’ ‘+ CAST( YEAR( CONVERT(datetime, ‘2017-02-01’,121)) AS VARCHAR(4)) AS Description Other way(using numbers and not date): (you can change months name abbrev.) SELECT SUBSTRING(‘GENFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC’,1+(MONTH_NUMB-1)*3,3)+’-‘+ RIGHT(YEAR_NUMB,2) AS M_DELIVERY , ‘DELIVERY … Read more

[Solved] Subquery returned more than 1 value. wrong if statement [closed]

You do not need any of these IF..ELSE statements or even the sub-queries in your select, what you are after, can be achieved with the following simple select query: CREATE PROC GET_ORDER_ACCOUNT_DETAILS @ORDERID INT AS BEGIN SET NOCOUNT ON; SELECT CASE WHEN od.calcType=”K” THEN od.price * od.kilo ELSE od.quant * od.price END as [AMOUNT] ,od.quant … Read more

[Solved] What is the difference between OUTER APPLY and OUTER JOIN, and when to use each? [closed]

First, I do not really know which is the default OUTER JOIN in T-SQL (I’d bet FULL), but in any case, I think it is unclear – it is best to use LEFT, RIGHT, OR FULL JOIN explicitly when you need one. JOIN joins tables. Already existent ones or subqueries. APPLY applies (duh) a table-valued … Read more

[Solved] How to do the c# string.split() in oracle

Replace the prefixes you want to remove, then find the index of the first and second underscores and then find the substring between those two separators: Oracle Setup: CREATE TABLE your_table ( value ) AS SELECT ‘DUM_EI_AO_L_5864_Al Meena Tower’ FROM DUAL UNION ALL SELECT ‘EI_AE_L_5864_Al radha Tower’ FROM DUAL Query: SELECT value, SUBSTR( replaced_value, first_separator … Read more