SQL query to get most recent row use asp.net+access - sql

select and get or retrieve a date from calendar control in ASP.Net to the table and select time from checkbox to the table.
output :: The most recent date and time is .....
table TEST
Date_From_Calendar | TIME |
---------------------|--------------|
15/12/2014 | 09.00-12.00 |
18/12/2014 | 15.00-18.00 |
18/12/2014 | 15.00-18.00 |
19/12/2014 | 15.00-18.00 |
19/12/2014 | 12.00-15.00 |
19/12/2014 | 12.00-15.00 |
19/12/2014 | 12.00-15.00 |
19/12/2014 | 09.00-12.00 |
20/12/2014 | 09.00-12.00 |
24/12/2014 | 09.00-12.00 |

SELECT Date_From_Calendar , MAX(TIME) AS TIME
FROM Table
GROUP BY Date_From_Calendar

Related

Postgresql query substract from one table

I have a one tables in Postgresql and cannot find how to build a query.
The table contains columns nr_serii and deleteing_time. I trying to count nr_serii and substract from this positions with deleting_time.
My query:
select nr_serii , count(nr_serii ) as ilosc,count(deleting_time) as ilosc_delete
from MyTable
group by nr_serii, deleting_time
output is:
+--------------------+
| "666666";1;1 |
| "456456";1;0 |
| "333333";3;0 |
| "333333";1;1 |
| "111111";1;1 |
| "111111";3;0 |
+--------------------+
The part of table with raw data:
+--------------------------------+
| "666666";"2020-11-20 14:08:13" |
| "456456";"" |
| "333333";"" |
| "333333";"" |
| "333333";"" |
| "333333";"2020-11-20 14:02:23" |
| "111111";"" |
| "111111";"" |
| "111111";"2020-11-20 14:08:04" |
| "111111";"" |
+--------------------------------+
And i need substract column ilosc and column ilosc_delete
example:
nr_serii:333333 ilosc:3-1=2
Expected output:
+-------------+
| "666666";-1 |
| "456456";1 |
| "333333";2 |
| "111111";2 |
| ... |
+-------------+
I think this is very simple solution for this but i have empty in my head.
I see what you want now. You want to subtract the number where deleting_time is not null from the ones where it is null:
select nr_serii,
count(*) filter (where deleting_time is null) - count(deleting_time) as ilosc_delete
from MyTable
group by nr_serii;
Here is a db<>fiddle.

How to select all columns of a bigquery table

I have the follow bigquery table:
+---------------------+-----------+-------------------------+-----------------+
| links.href | links.rel | dados.dataHora | dados.sequencia |
+---------------------+-----------+-------------------------+-----------------+
| https://www.url.com | self | 2017-03-16 16:27:10 UTC | 2 |
| | | 2017-03-16 16:35:34 UTC | 1 |
| | | 2017-03-16 19:50:32 UTC | 3 |
+---------------------+-----------+-------------------------+-----------------+
and I want select all rows. So, I try the follow query:
SELECT * FROM [my_project:a_import.my_table] LIMIT 100
But, I have a bad (and sad) error:
Error: Cannot output multiple independently repeated fields at the same time. Found links_rel and dados_dataHora
Please, can anybody help me?

Multiple Rows in to One Row

I have a result set in oracle as below: let the table name t1
Name | phase| a_plan | a_actual | b_plan | b_actual | c_plan | c_actual
===================================================================================
RKM | m5-m6| 1/1/2014|1/6/2014 | 2/2/2014 | | 3/3/2014|
RKM | m5-m6| 1/1/2014| | 2/2/2014 | 4/2/2014 | 3/3/2014|
RKM | m5-m6| 1/1/2014| | 2/2/2014 | | 3/3/2014| 5/3/2014
Whereas I need the result set as below in a single row:(a-Plan, b_plan,c_plan will be same across all 3 rows only actual column chnages per row)
Name | phase| a_plan | a_actual | b_plan | b_actual | c_plan | c_actual
===================================================================================
RKM | m5-m6| 1/1/2014|1/6/2014 | 2/2/2014 | 4/2/2014 | 3/3/2014| 5/3/2014
Help in framing the query?
SELECT NAME,
phase,
a_plan,
Max(a_actual),
b_plan,
Max(b_actual),
c_plan,
Max(c_actual)
FROM table
GROUP BY NAME,
phase,
a_plan,
b_plan,
c_plan
/

casting a REAL as INT and comparing

I am casting a real to an int and a float to an int and comparing the two like this:
where
cast(a.[SUM(PAID_AMT)] as int)!=cast(b.PAID_AMT as int)
but i am still getting results where the two are equal. for example:
+-----------+-----------+------------+------------+----------+
| accn | load_dt | pmtdt | sumpaidamt | Bpaidamt |
+-----------+-----------+------------+------------+----------+
| A133312 | 6/7/2011 | 11/28/2011 | 98.39 | 98.39 |
| A445070 | 6/2/2011 | 9/22/2011 | 204.93 | 204.93 |
| A465606 | 5/19/2011 | 10/19/2011 | 560.79 | 560.79 |
| A508742 | 7/12/2011 | 10/19/2011 | 279.65 | 279.65 |
| A567730 | 5/27/2011 | 10/24/2011 | 212.76 | 212.76 |
| A617277 | 7/12/2011 | 10/12/2011 | 322.02 | 322.02 |
| A626384 | 6/16/2011 | 10/21/2011 | 415.84 | 415.84 |
| AA0000044 | 5/12/2011 | 5/23/2011 | 197.38 | 197.38 |
+-----------+-----------+------------+------------+----------+
here is the full query:
select
a.accn,
a.load_dt,
a.pmtdt,
a.[SUM(PAID_AMT)] sumpaidamt,
sum(b.paid_amt) Bpaidamt
from
[MILLENNIUM_DW_DEV].[dbo].[Millennium_Payment_Data_May2011_July2012] a
join
F_PAYOR_PAYMENTS_DAILY b
on
a.accn=b.ACCESSION_ID
and
a.final_rpt_dt=b.FINAL_REPORT_DATE
and
a.load_dt=b.LOAD_DATE
and
a.pmtdt=b.PAYMENT_DATE
where
cast(a.[SUM(PAID_AMT)] as int)!=cast(b.PAID_AMT as int)
group by
a.accn,
a.load_dt,
a.pmtdt,
a.[SUM(PAID_AMT)]
what am i doing wrong? how do i return only records that are NOT equal?
I don't see why there is an issue.
The query is returning the sum of the payments in b (sum(b.paid_amt) Bpaidamt). The where clause is comparing individual payments. This just means that there is more than one payment.
Perhaps your intention is to have a HAVING clause instead:
having cast(a.[SUM(PAID_AMT)] as int)!=cast(sum(b.PAID_AMT) as int)
You can do a round and a cast statement.
cast(round(sumpaidamt,2) as money) <> cast(round(Bpaidamt,2) as money)
Sql Fiddle showing how it would work http://sqlfiddle.com/#!3/4eb79/1

How do I retrieve 10 days data up to date 'XYZ' from mysql with Perl when some days data are missing, i.e. public holidays

Data is put into a MYSQL DB in the following format:
| 2010-03-18 | 1.580 | 1.590 | 1.560 | 1.580 | 164500 | 1.580 |
| 2010-03-19 | 1.570 | 1.570 | 1.560 | 1.570 | 178300 | 1.570 |
| 2010-03-22 | 1.550 | 1.560 | 1.540 | 1.560 | 309000 | 1.560 |
| 2010-03-23 | 1.560 | 1.560 | 1.550 | 1.550 | 284900 | 1.550 |
I need to select 10 days of data upto date XYZ, the problem is that some days are missing, i.e. public holidays.
If you want a ten-day range of data, use WHERE. As in,
SELECT * FROM table WHERE date >= '2010-03-22' AND date <= '2010-03-31' ;
If you want ten records, ending a certain day, use ORDER BY and LIMIT:
SELECT * FROM table WHERE date <= '2010-03-31' ORDER BY date DESC LIMIT 10 ;